Add 401 unauthorized http error

This commit is contained in:
Alice Gaudon 2020-07-08 11:33:01 +02:00
parent 724d59daba
commit 5b80c3ac07
2 changed files with 12 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{
"name": "wms-core",
"version": "0.10.22",
"version": "0.10.23",
"description": "Node web framework",
"repository": "git@gitlab.com:ArisuOngaku/wms-core.git",
"author": "Alice Gaudon <alice@gaudon.pro>",

View File

@ -3,7 +3,7 @@ import {WrappingError} from "./Utils";
export abstract class HttpError extends WrappingError {
public readonly instructions: string;
constructor(message: string, instructions: string, cause?: Error) {
protected constructor(message: string, instructions: string, cause?: Error) {
super(message, cause);
this.instructions = instructions;
}
@ -28,6 +28,16 @@ export class BadRequestError extends HttpError {
}
}
export class UnauthorizedHttpError extends BadRequestError {
constructor(message: string, url: string, cause?: Error) {
super(message, '', url, cause);
}
get errorCode(): number {
return 401;
}
}
export class ForbiddenHttpError extends BadRequestError {
constructor(thing: string, url: string, cause?: Error) {
super(