Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

fix(errorHandler): application errors would result in a 200 response #1243

Merged
merged 3 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions __tests__/server/ssrServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,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 () => {
Expand Down Expand Up @@ -709,6 +710,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);
});
});
});
1 change: 1 addition & 0 deletions src/server/ssrServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ async function appPlugin(fastify) {

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);
});
}
Expand Down
Loading