Skip to content

Commit

Permalink
Added RangeNotSatisfiableError error
Browse files Browse the repository at this point in the history
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
  • Loading branch information
daniellockyer committed Mar 11, 2024
1 parent 656b480 commit 83f01b2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/errors/src/errors.ts
Expand Up @@ -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, {
Expand Down
9 changes: 9 additions & 0 deletions packages/errors/test/errors.test.ts
Expand Up @@ -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);
Expand Down

0 comments on commit 83f01b2

Please sign in to comment.