From 40e760facb18174a92203cad9606b68ca3ef423c Mon Sep 17 00:00:00 2001 From: Jamie King Date: Fri, 19 Jan 2024 16:23:37 -0700 Subject: [PATCH] fix(errorHandler): application errors would result in a 200 response --- __tests__/server/ssrServer.spec.js | 2 ++ src/server/ssrServer.js | 1 + 2 files changed, 3 insertions(+) diff --git a/__tests__/server/ssrServer.spec.js b/__tests__/server/ssrServer.spec.js index 4ced03a43..c8200d57f 100644 --- a/__tests__/server/ssrServer.spec.js +++ b/__tests__/server/ssrServer.spec.js @@ -913,6 +913,7 @@ describe('ssrServer', () => { '"Fastify application error: method get, url "/example", correlationId "undefined", headersSent: false [Error: testing]"' ); expect(renderStaticErrorPage).toHaveBeenCalledWith(request, reply); + expect(reply.code).toHaveBeenCalledWith(500); }); test('setErrorHandler logs an error and renders the static error page with "headersSent" and "correlationId"', async () => { @@ -946,6 +947,7 @@ describe('ssrServer', () => { '"Fastify application error: method get, url "/example", correlationId "123", headersSent: true [Error: testing]"' ); expect(renderStaticErrorPage).toHaveBeenCalledWith(request, reply); + expect(reply.code).toHaveBeenCalledWith(500); }); }); }); diff --git a/src/server/ssrServer.js b/src/server/ssrServer.js index a9cd05064..a78ee2e7c 100644 --- a/src/server/ssrServer.js +++ b/src/server/ssrServer.js @@ -244,6 +244,7 @@ export async function createApp(opts = {}) { request.log.error('Fastify application error: method %s, url "%s", correlationId "%s", headersSent: %s', method, url, correlationId, headersSent, error); + reply.code(500); return renderStaticErrorPage(request, reply); });