Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: export 406 and rename 413 #448

Merged
merged 2 commits into from
Nov 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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