Skip to content

Commit

Permalink
Add detail generic to ApiError
Browse files Browse the repository at this point in the history
  • Loading branch information
haythamlabrini committed May 7, 2020
1 parent d38c61e commit 94a300a
Show file tree
Hide file tree
Showing 3 changed files with 5,433 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ yarn add @icapps/tree-house-errors

## Error types

### ApiError
### ApiError<T>

Base error class which extends from the `Error` class.
`ApiError` accepts a generic `T` for the `details` property; if not specified, it defaults to `any`.

```javascript
// All keys are required
Expand Down
6 changes: 3 additions & 3 deletions src/lib/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import * as httpStatus from 'http-status';

import { errors } from '../config/errors.config';

export class ApiError extends Error {
export class ApiError<T = any> extends Error {
code: string;
status: number;
i18n?: string;
id?: string;
detail?: any;
detail?: T;
isApiError: boolean;

constructor(status: number, error: ErrorType, args: { message?: string, detail?: any, stack?: any } = {}) {
constructor(status: number, error: ErrorType, args: { message?: string, detail?: T, stack?: any } = {}) {
const { message, detail, stack } = args;
super(message || error.message);
this.name = 'ApiError';
Expand Down

0 comments on commit 94a300a

Please sign in to comment.