From 8e49bd321847ef2faeb425dda5344bdfa01bed93 Mon Sep 17 00:00:00 2001 From: Fabian Stamm Date: Sat, 10 Mar 2018 16:40:59 +0100 Subject: [PATCH] adding type property on errors --- index.d.ts | 3 +++ index.js | 12 +++++++++--- index.ts | 6 ++++++ test.d.ts | 1 + 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index 1998adb..227f156 100644 --- a/index.d.ts +++ b/index.d.ts @@ -31,11 +31,14 @@ export default class SecureFile { history(id: string): Promise; } export declare class Unauthorized extends Error { + type: string; constructor(); } export declare class NotFound extends Error { + type: string; constructor(); } export declare class BadRequest extends Error { + type: string; constructor(); } diff --git a/index.js b/index.js index 7aa8800..0775ef1 100644 --- a/index.js +++ b/index.js @@ -270,7 +270,9 @@ exports.default = SecureFile; var Unauthorized = /** @class */ (function (_super) { __extends(Unauthorized, _super); function Unauthorized() { - return _super.call(this, "Not authorized") || this; + var _this = _super.call(this, "Not authorized") || this; + _this.type = "unauthorized"; + return _this; } return Unauthorized; }(Error)); @@ -278,7 +280,9 @@ exports.Unauthorized = Unauthorized; var NotFound = /** @class */ (function (_super) { __extends(NotFound, _super); function NotFound() { - return _super.call(this, "Not found") || this; + var _this = _super.call(this, "Not found") || this; + _this.type = "notfound"; + return _this; } return NotFound; }(Error)); @@ -286,7 +290,9 @@ exports.NotFound = NotFound; var BadRequest = /** @class */ (function (_super) { __extends(BadRequest, _super); function BadRequest() { - return _super.call(this, "Bad request") || this; + var _this = _super.call(this, "Bad request") || this; + _this.type = "badrequest"; + return _this; } return BadRequest; }(Error)); diff --git a/index.ts b/index.ts index 5b35893..856a135 100644 --- a/index.ts +++ b/index.ts @@ -139,20 +139,26 @@ export default class SecureFile { } export class Unauthorized extends Error { + type: string; constructor() { super("Not authorized"); + this.type = "unauthorized" } } export class NotFound extends Error { + type: string; constructor() { super("Not found"); + this.type = "notfound" } } export class BadRequest extends Error { + type: string; constructor() { super("Bad request"); + this.type = "badrequest" } } diff --git a/test.d.ts b/test.d.ts index e69de29..cb0ff5c 100644 --- a/test.d.ts +++ b/test.d.ts @@ -0,0 +1 @@ +export {};