Skip to content

Commit

Permalink
Merge pull request #2 from aloukissas/honor-status-code
Browse files Browse the repository at this point in the history
Honor error code in response
  • Loading branch information
matthewkeil authored Dec 3, 2022
2 parents 31868ce + 7803364 commit 8133a84
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 4 deletions.
2 changes: 0 additions & 2 deletions src/convertResponse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ describe('convertResponse()', () => {
expect(res.send).toHaveBeenCalledWith(defaultResponse.body);
expect(res.status).toBeCalledTimes(1);
expect(res.status).toHaveBeenCalledWith(defaultResponse.statusCode);
expect(res.end).toBeCalledTimes(1);
expect(res.end).toHaveBeenCalledWith();
});

it('should set a default statusCode', () => {
Expand Down
3 changes: 1 addition & 2 deletions src/convertResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,9 @@ export function convertResponseFactory({
const coerced = isObject(response) && 'body' in response ? coerceBody(response.body) : coerceBody(response);
logger.info('End - Result:');
logger.info(coerced);
res.send(coerced);

const statusCode = isObject(response) && !!response.statusCode ? parseInt(`${response.statusCode}`) : 200;
return res.status(statusCode).end();
return res.status(statusCode).send(coerced);
} catch (error) {
return sendError(error as Error);
}
Expand Down

0 comments on commit 8133a84

Please sign in to comment.