From 83f01b2edf5015bc6fb57ccf2e23c97dcabca071 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Mon, 11 Mar 2024 16:50:29 +0100 Subject: [PATCH] Added RangeNotSatisfiableError error ref ENG-729 ref https://linear.app/tryghost/issue/ENG-729/incorrect-range-header-leads-to-http-500-errors - this will be used when the content Ghost is trying to serve cannot be satisfied for the provided range --- packages/errors/src/errors.ts | 11 +++++++++++ packages/errors/test/errors.test.ts | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/packages/errors/src/errors.ts b/packages/errors/src/errors.ts index 8be63a23..2bd84146 100644 --- a/packages/errors/src/errors.ts +++ b/packages/errors/src/errors.ts @@ -137,6 +137,17 @@ export class RequestNotAcceptableError extends GhostError { } } +export class RangeNotSatisfiableError extends GhostError { + constructor(options: GhostErrorOptions = {}) { + super(mergeOptions(options, { + statusCode: 416, + errorType: 'RangeNotSatisfiableError', + message: 'Range not satisfiable for provided Range header.', + hideStack: true + })); + } +} + export class RequestEntityTooLargeError extends GhostError { constructor(options: GhostErrorOptions = {}) { super(mergeOptions(options, { diff --git a/packages/errors/test/errors.test.ts b/packages/errors/test/errors.test.ts index ed3e61cd..0d6e929e 100644 --- a/packages/errors/test/errors.test.ts +++ b/packages/errors/test/errors.test.ts @@ -488,6 +488,15 @@ Line 2 - Help`); error.hideStack.should.be.false(); }); + it('RangeNotSatisfiableError', function () { + const error = new errors.RangeNotSatisfiableError(); + error.statusCode.should.eql(416); + error.level.should.eql('normal'); + error.errorType.should.eql('RangeNotSatisfiableError'); + error.message.should.eql('Range not satisfiable for provided Range header.'); + error.hideStack.should.be.true(); + }); + it('TokenRevocationError', function () { const error = new errors.TokenRevocationError(); error.statusCode.should.eql(503);