diff --git a/src/getFileContents.ts b/src/getFileContents.ts index d8bfc1d..1f64ac2 100644 --- a/src/getFileContents.ts +++ b/src/getFileContents.ts @@ -13,25 +13,27 @@ export const getFileContents: () => Promise = () => new Promise((resolve host: 'cdn-patch.swtor.com', path, }, (response) => { - console.log(`STATUS: ${response.statusCode}`); - console.log(`HEADERS: ${JSON.stringify(response.headers)}`); + if (response.statusCode !== 200) { + return reject(`Expected status code 200 but received ${response.statusCode}`); + } + const headerLength = Number(response.headers['content-length']); const chunkList: Buffer[] = []; let totalLength = 0; response.on('data', (chunk: Buffer) => { - console.log(`BODY: ${chunk.length}`); chunkList.push(chunk); totalLength += chunk.length; }); response.on('end', () => { - console.log('No more data in response.'); + if (totalLength !== headerLength) { + return reject(`Expected length ${headerLength} but received ${totalLength}`); + } const fileContents = Buffer.concat(chunkList, totalLength); resolve(fileContents); }); }); request.on('error', (e) => { - console.error(`problem with request: ${e.message}`); reject(e); }); request.end();