From 7803364239cf1e2935cffeb9aca9cc0bcaa6596f Mon Sep 17 00:00:00 2001 From: Alex Loukissas Date: Fri, 2 Dec 2022 16:07:16 -0800 Subject: [PATCH] Honor error code in response --- src/convertResponse.spec.ts | 2 -- src/convertResponse.ts | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/convertResponse.spec.ts b/src/convertResponse.spec.ts index 72e3651..85cea78 100644 --- a/src/convertResponse.spec.ts +++ b/src/convertResponse.spec.ts @@ -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', () => { diff --git a/src/convertResponse.ts b/src/convertResponse.ts index 30460ed..4fc1b59 100644 --- a/src/convertResponse.ts +++ b/src/convertResponse.ts @@ -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); }