Skip to content

Commit

Permalink
fix: export 406 and rename 413 (#448)
Browse files Browse the repository at this point in the history
* Export NotAcceptable error type

* Rename RequestEntityTooLarge error type
  • Loading branch information
Guillaume authored Nov 7, 2020
1 parent 80ca68f commit 0f48f1f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/framework/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ export class HttpError extends Error implements ValidationError {
}):
| InternalServerError
| UnsupportedMediaType
| RequestEntityToLarge
| RequestEntityTooLarge
| BadRequest
| MethodNotAllowed
| NotAcceptable
Expand All @@ -542,7 +542,7 @@ export class HttpError extends Error implements ValidationError {
case 406:
return new NotAcceptable(err);
case 413:
return new RequestEntityToLarge(err);
return new RequestEntityTooLarge(err);
case 415:
return new UnsupportedMediaType(err);
default:
Expand Down Expand Up @@ -613,7 +613,7 @@ export class BadRequest extends HttpError {
}
}

export class RequestEntityToLarge extends HttpError {
export class RequestEntityTooLarge extends HttpError {
constructor(err: {
path: string;
message?: string;
Expand Down
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { OpenApiSpecLoader } from './framework/openapi.spec.loader';
import {
InternalServerError,
UnsupportedMediaType,
RequestEntityToLarge,
RequestEntityTooLarge,
BadRequest,
MethodNotAllowed,
NotAcceptable,
NotFound,
Unauthorized,
Forbidden,
Expand All @@ -19,9 +20,10 @@ export const middleware = openapiValidator;
export const error = {
InternalServerError,
UnsupportedMediaType,
RequestEntityToLarge,
RequestEntityTooLarge,
BadRequest,
MethodNotAllowed,
NotAcceptable,
NotFound,
Unauthorized,
Forbidden,
Expand Down
2 changes: 1 addition & 1 deletion src/middlewares/openapi.multipart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function error(req: OpenApiRequest, err: Error): ValidationError {
message: err.message,
});
/*return payload_too_big
? new RequestEntityToLarge({ path: req.path, message: err.message })
? new RequestEntityTooLarge({ path: req.path, message: err.message })
: !unexpected
? new BadRequest({ path: req.path, message: err.message })
: new InternalServerError({ path: req.path, message: err.message });*/
Expand Down
3 changes: 2 additions & 1 deletion src/openapi.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ export {
OpenApiValidatorOpts,
InternalServerError,
UnsupportedMediaType,
RequestEntityToLarge,
RequestEntityTooLarge,
BadRequest,
MethodNotAllowed,
NotAcceptable,
NotFound,
Unauthorized,
Forbidden,
Expand Down
14 changes: 7 additions & 7 deletions test/httperror.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,21 @@ describe(packageJson.name, () => {
done();
});

it('should be an instance of RequestEntityToLarge', (done) => {
console.log('Testing instaceof detection of RequestEntityToLarge');
it('should be an instance of RequestEntityTooLarge', (done) => {
console.log('Testing instaceof detection of RequestEntityTooLarge');
const err = {
path: '/entity_to_large',
message: 'request qntity too large',
path: '/entity_too_large',
message: 'request entity too large',
};
expect(new error.RequestEntityToLarge(err)).to.be.an.instanceof(
error.RequestEntityToLarge,
expect(new error.RequestEntityTooLarge(err)).to.be.an.instanceof(
error.RequestEntityTooLarge,
);
expect(
HttpError.create({
status: 413,
...err,
}),
).to.be.an.instanceof(error.RequestEntityToLarge);
).to.be.an.instanceof(error.RequestEntityTooLarge);
done();
});

Expand Down

0 comments on commit 0f48f1f

Please sign in to comment.