Skip to content

Commit

Permalink
From else-if to switch for status checking
Browse files Browse the repository at this point in the history
  • Loading branch information
efabris committed May 22, 2020
1 parent 781a171 commit 27a4bd0
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/framework/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,6 @@ export class HttpError extends Error implements ValidationError {
public static create(err: {
status: number;
path: string;
name: string;
message?: string;
errors?: ValidationErrorItem[];
}):
Expand All @@ -512,22 +511,23 @@ export class HttpError extends Error implements ValidationError {
| NotFound
| Unauthorized
| Forbidden {
if (err.status == 400) {
return new BadRequest(err);
} else if (err.status == 401) {
return new Unauthorized(err);
} else if (err.status == 403) {
return new Forbidden(err);
} else if (err.status == 404) {
return new NotFound(err);
} else if (err.status == 405) {
return new MethodNotAllowed(err);
} else if (err.status == 413) {
return new RequestEntityToLarge(err);
} else if (err.status == 415) {
return new UnsupportedMediaType(err);
} else {
return new InternalServerError(err);
switch (err.status) {
case 400:
return new BadRequest(err);
case 401:
return new Unauthorized(err);
case 403:
return new Forbidden(err);
case 404:
return new NotFound(err);
case 405:
return new MethodNotAllowed(err);
case 413:
return new RequestEntityToLarge(err);
case 415:
return new UnsupportedMediaType(err);
default:
return new InternalServerError(err);
}
}
}
Expand Down

0 comments on commit 27a4bd0

Please sign in to comment.