Skip to content

Commit da09edb

Browse files
committed
added status code for 419 Page Expired errors 10m
1 parent c8f3bad commit da09edb

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

src/Status.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ export const codes: Record<string, ResponseStatus> = {
191191
// The user agent requested a resource that cannot legally
192192
// be provided, such as a web page censored by a government.
193193
LEGAL_REASONS: { code: 451, status: 'Unavailable For Legal Reasons' },
194+
// This status code means that the CSRF token sent by the client is incorrect
195+
// or missing. This is used to prevent Cross-Site Request Forgery attacks.
196+
PAGE_EXPIRED: { code: 419, status: 'Page Expired' },
194197

195198
//------------------------------------------------------------------//
196199
// 500 Status Codes
@@ -288,6 +291,7 @@ const Status = {
288291
TOO_MANY: codes.TOO_MANY,
289292
HEADER_TOO_LARGE: codes.HEADER_TOO_LARGE,
290293
LEGAL_REASONS: codes.LEGAL_REASONS,
294+
PAGE_EXPIRED: codes.PAGE_EXPIRED,
291295

292296
//------------------------------------------------------------------//
293297
// 500 Status Codes

tests/Exception.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,15 @@ describe('Exception Tests', () => {
229229
expect(response.status).to.equal('Unknown');
230230
});
231231

232+
it('Should handle page expired error', () => {
233+
try {
234+
throw Exception.for('Page expired').withCode(419);
235+
} catch (e) {
236+
const exception = Exception.upgrade(e as Error);
237+
const response = exception.toResponse();
238+
expect(response.code).to.equal(419);
239+
expect(response.status).to.equal('Page Expired');
240+
expect(response.error).to.equal('Page expired');
241+
}
242+
});
232243
});

0 commit comments

Comments
 (0)