Skip to content

Commit

Permalink
fix: handle body not being object
Browse files Browse the repository at this point in the history
  • Loading branch information
dubisdev committed Dec 2, 2022
1 parent edec7b1 commit 8c7b56d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ function getRequestBody(req: IncomingMessage): Promise<DoistCardRequest> {
return new Promise((resolve, reject) => {
let body = '';
req.on('data', chunk => body += chunk.toString());
req.on('end', () => resolve(JSON.parse(body)));
req.on('end', () => {
try {
const result = JSON.parse(body);
resolve(result);
} catch (err) { reject(err); }
});
req.on('error', err => reject(err));
});
}
Expand Down

0 comments on commit 8c7b56d

Please sign in to comment.