diff options
| author | THarley | 2018-02-22 17:19:08 +0000 |
|---|---|---|
| committer | THarley | 2018-02-22 17:19:08 +0000 |
| commit | 3198c6c2474101623e3b95bd038effe210c176a8 (patch) | |
| tree | 318483b8b380383ad9ddec6d606544375d3f6a8b /src/errors/errorware.ts | |
| parent | Merge branch 'trh/error-middleware' into 'master' (diff) | |
| download | medicine-3198c6c2474101623e3b95bd038effe210c176a8.tar.gz medicine-3198c6c2474101623e3b95bd038effe210c176a8.zip | |
Revert “Merge branch ‘trh/error-middleware’ into ‘master’”
This reverts merge request !13
Diffstat (limited to 'src/errors/errorware.ts')
| -rw-r--r-- | src/errors/errorware.ts | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/src/errors/errorware.ts b/src/errors/errorware.ts deleted file mode 100644 index 8b7e015..0000000 --- a/src/errors/errorware.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { NextFunction, Request, Response } from 'express'; - -export interface ErrorResponseBlock { - status: string; - error: string; - error_description?: string; - user_message?: string; - // tslint:disable-next-line:no-any - error_data?: any; -} - -export class RequestError extends Error { - public code: number; - public userMessage?: string; - // tslint:disable-next-line:no-any - public errorData?: any; - - public constructor( - errCode: number = 500, - errName: string = 'internal_server_error', - errDescription?: string, - errUserMessage?: string, - // tslint:disable-next-line:no-any - errData?: any - ) { - super(errDescription); - this.code = errCode; - this.name = errName; - this.userMessage = errUserMessage; - this.errorData = errData; - } - - public responseBlock(): ErrorResponseBlock { - return { - status: 'error', - error: this.name, - error_description: this.message, - user_message: this.userMessage, - error_data: this.errorData - }; - } -} - -type Errorware = - (err: RequestError, req: Request, res: Response, next: NextFunction) => void; - -export const errorHandler: Errorware = - (err: RequestError, req: Request, res: Response, next: NextFunction): void => { - res.status(err.code) - .json(err.responseBlock()); -}; |
