From 5b80c3ac0775d87884e2c86d0227c690182450c9 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Wed, 8 Jul 2020 11:33:01 +0200 Subject: [PATCH] Add 401 unauthorized http error --- package.json | 2 +- src/HttpError.ts | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b17fd94..069e0e7 100644 --- a/package.json +++ b/package.json @@ -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 ", diff --git a/src/HttpError.ts b/src/HttpError.ts index 3e7b314..e76ace4 100644 --- a/src/HttpError.ts +++ b/src/HttpError.ts @@ -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(