fix(api-gateway): checking for buffer length

This commit is contained in:
Karol Sójko 2023-11-14 14:09:10 +01:00
parent 2823ed8612
commit f65809ef30
No known key found for this signature in database
GPG key ID: C2F813669419D05F

View file

@ -78,7 +78,9 @@ void container.load().then((container) => {
limit: '50mb',
verify: (_req: IncomingMessage, _res: ServerResponse, buf: Buffer, encoding: string): void => {
try {
JSON.parse(buf.toString(encoding as BufferEncoding))
if (buf && buf.length > 0) {
JSON.parse(buf.toString(encoding as BufferEncoding | 'utf8'))
}
} catch (error) {
logger.error(`Invalid JSON: ${(error as Error).message}. Request body: ${buf.toString()}`)
}