Skip to content
This repository has been archived by the owner on May 7, 2022. It is now read-only.

Commit

Permalink
update(🚚): nullable type + refactor exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
osamaqarem committed Jun 18, 2020
1 parent 38aa6df commit 7c07a84
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
24 changes: 12 additions & 12 deletions template/src/common/exceptions/BaseException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,34 @@
* 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<number | string>
private _message: Nullable<string>
private _url: Nullable<string>
private _originalError: Nullable<object>
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<object> {
return this._originalError
}

constructor(status: number | string, message: string, url: string, originalError: object) {
constructor(status: Nullable<number | string> = 'unknown', message: Nullable<string> = 'unknown', url: Nullable<string> = 'unknown', originalError: Nullable<object>) {
super()

this._status = status
this._message = message
this._url = url
this._originalError = originalError
}
}
}
6 changes: 3 additions & 3 deletions template/src/common/exceptions/HttpException.ts
Original file line number Diff line number Diff line change
@@ -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<number | string> = 'unknown', message: Nullable<string> = 'unknown', url: Nullable<string> = 'unknown', originalError: Nullable<object>) {
super(status, message, url, originalError)
this._type = 'HttpException'
}
}
}
8 changes: 8 additions & 0 deletions template/src/common/exceptions/HttpTimeoutException.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import BaseException from "./BaseException"

export default class HttpTimeoutException extends BaseException {
constructor(status: Nullable<number | string> = 'unknown', message: Nullable<string> = 'unknown', url: Nullable<string> = 'unknown', originalError: Nullable<object>) {
super(status, message, url, originalError)
this._type = 'HttpTimeoutException'
}
}
1 change: 1 addition & 0 deletions template/src/common/types/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare type Nullable<T> = T | null | undefined

0 comments on commit 7c07a84

Please sign in to comment.