From da09edb79f0d77dc97cecdc40b629890a508d2f5 Mon Sep 17 00:00:00 2001 From: cdsiats <118641404+cdsiats@users.noreply.github.com> Date: Thu, 16 Apr 2026 16:10:18 +0800 Subject: [PATCH] added status code for 419 Page Expired errors 10m --- src/Status.ts | 4 ++++ tests/Exception.test.ts | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/Status.ts b/src/Status.ts index e6de509..12c6946 100644 --- a/src/Status.ts +++ b/src/Status.ts @@ -191,6 +191,9 @@ export const codes: Record = { // 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 @@ -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 diff --git a/tests/Exception.test.ts b/tests/Exception.test.ts index 7a0b540..bd4a1a6 100644 --- a/tests/Exception.test.ts +++ b/tests/Exception.test.ts @@ -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'); + } + }); }); \ No newline at end of file