From 7c07a84524c76ee62a1832574a524cca56bb794b Mon Sep 17 00:00:00 2001 From: Osama Qarem Date: Thu, 18 Jun 2020 23:36:51 +0800 Subject: [PATCH] =?UTF-8?q?update(=F0=9F=9A=9A):=20nullable=20type=20+=20r?= =?UTF-8?q?efactor=20exceptions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/common/exceptions/BaseException.ts | 24 +++++++++---------- .../src/common/exceptions/HttpException.ts | 6 ++--- .../common/exceptions/HttpTimeoutException.ts | 8 +++++++ template/src/common/types/types.d.ts | 1 + 4 files changed, 24 insertions(+), 15 deletions(-) create mode 100644 template/src/common/exceptions/HttpTimeoutException.ts create mode 100644 template/src/common/types/types.d.ts diff --git a/template/src/common/exceptions/BaseException.ts b/template/src/common/exceptions/BaseException.ts index 5380edb..cf80914 100644 --- a/template/src/common/exceptions/BaseException.ts +++ b/template/src/common/exceptions/BaseException.ts @@ -2,29 +2,29 @@ * All custom exceptions should extend this class. */ export default class BaseException extends Error { - private _status: number | string - private _message: string - private _url: string - private _originalError: object - public _type: string = 'BaseException' + private _status: Nullable + private _message: Nullable + private _url: Nullable + private _originalError: Nullable + public _type = 'BaseException' - get status(): number | string { + get status() { return this._status } - get message(): string { - return this._message + get message() { + return this._message || 'unknown' } - get url(): string { + get url() { return this._url } - get originalError(): object { + get originalError(): Nullable { return this._originalError } - constructor(status: number | string, message: string, url: string, originalError: object) { + constructor(status: Nullable = 'unknown', message: Nullable = 'unknown', url: Nullable = 'unknown', originalError: Nullable) { super() this._status = status @@ -32,4 +32,4 @@ export default class BaseException extends Error { this._url = url this._originalError = originalError } -} +} \ No newline at end of file diff --git a/template/src/common/exceptions/HttpException.ts b/template/src/common/exceptions/HttpException.ts index 0a7c684..8e6c6f7 100644 --- a/template/src/common/exceptions/HttpException.ts +++ b/template/src/common/exceptions/HttpException.ts @@ -1,8 +1,8 @@ import BaseException from "./BaseException" export default class HttpException extends BaseException { - constructor(status: number | string, message: string, url: string, originalError: object) { - super(status, message, url, originalError); + constructor(status: Nullable = 'unknown', message: Nullable = 'unknown', url: Nullable = 'unknown', originalError: Nullable) { + super(status, message, url, originalError) this._type = 'HttpException' } -} +} \ No newline at end of file diff --git a/template/src/common/exceptions/HttpTimeoutException.ts b/template/src/common/exceptions/HttpTimeoutException.ts new file mode 100644 index 0000000..c31e7c6 --- /dev/null +++ b/template/src/common/exceptions/HttpTimeoutException.ts @@ -0,0 +1,8 @@ +import BaseException from "./BaseException" + +export default class HttpTimeoutException extends BaseException { + constructor(status: Nullable = 'unknown', message: Nullable = 'unknown', url: Nullable = 'unknown', originalError: Nullable) { + super(status, message, url, originalError) + this._type = 'HttpTimeoutException' + } +} \ No newline at end of file diff --git a/template/src/common/types/types.d.ts b/template/src/common/types/types.d.ts new file mode 100644 index 0000000..e2bc636 --- /dev/null +++ b/template/src/common/types/types.d.ts @@ -0,0 +1 @@ +declare type Nullable = T | null | undefined \ No newline at end of file