Skip to content
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
4 changes: 4 additions & 0 deletions src/Status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ export const codes: Record<string, ResponseStatus> = {
// The user agent requested a resource that cannot legally
// be provided, such as a web page censored by a government.
LEGAL_REASONS: { code: 451, status: 'Unavailable For Legal Reasons' },
// This status code means that the CSRF token sent by the client is incorrect
// or missing. This is used to prevent Cross-Site Request Forgery attacks.
PAGE_EXPIRED: { code: 419, status: 'Page Expired' },

//------------------------------------------------------------------//
// 500 Status Codes
Expand Down Expand Up @@ -288,6 +291,7 @@ const Status = {
TOO_MANY: codes.TOO_MANY,
HEADER_TOO_LARGE: codes.HEADER_TOO_LARGE,
LEGAL_REASONS: codes.LEGAL_REASONS,
PAGE_EXPIRED: codes.PAGE_EXPIRED,

//------------------------------------------------------------------//
// 500 Status Codes
Expand Down
11 changes: 11 additions & 0 deletions tests/Exception.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,15 @@ describe('Exception Tests', () => {
expect(response.status).to.equal('Unknown');
});

it('Should handle page expired error', () => {
try {
throw Exception.for('Page expired').withCode(419);
} catch (e) {
const exception = Exception.upgrade(e as Error);
const response = exception.toResponse();
expect(response.code).to.equal(419);
expect(response.status).to.equal('Page Expired');
expect(response.error).to.equal('Page expired');
}
});
});
Loading