unify-errors
Advanced tools
Comparing version
/** | ||
* Context is used to pass informal data to the exception, | ||
* We used a string any record to keep the flexibility. | ||
* We used a string record to keep the flexibility. | ||
*/ | ||
@@ -5,0 +5,0 @@ export declare type CustomErrorContext = Record<string, unknown>; |
{ | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"license": "MIT", | ||
@@ -60,12 +60,12 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@size-limit/preset-small-lib": "^7.0.8", | ||
"husky": "^7.0.4", | ||
"size-limit": "^7.0.8", | ||
"tsdx": "^0.14.1", | ||
"tslib": "^2.3.1", | ||
"typescript": "^4.5.5", | ||
"@size-limit/preset-small-lib": "7.0.8", | ||
"husky": "7.0.4", | ||
"size-limit": "7.0.8", | ||
"tsdx": "0.14.1", | ||
"tslib": "2.3.1", | ||
"typescript": "4.6.3", | ||
"np": "7.6.0", | ||
"prettier": "2.6.0", | ||
"@typescript-eslint/eslint-plugin": "5.15.0", | ||
"@typescript-eslint/parser": "5.15.0", | ||
"@typescript-eslint/eslint-plugin": "5.18.0", | ||
"@typescript-eslint/parser": "5.18.0", | ||
"eslint": "8.11.0", | ||
@@ -72,0 +72,0 @@ "eslint-config-prettier": "8.5.0", |
@@ -1,2 +0,3 @@ | ||
[](https://codeclimate.com/github/flexper/unify-errors/test_coverage) [](https://codeclimate.com/github/flexper/unify-errorss/maintainability) | ||
[](https://codeclimate.com/github/flexper/unify-errors/test_coverage) [](https://codeclimate.com/github/flexper/unify-errorss/maintainability)     | ||
# Unify errors | ||
@@ -18,2 +19,52 @@ | ||
## API | ||
### BadRequest(context?) | ||
Return: CustomError with Bad Request message. | ||
### Unauthorized(context?) | ||
Return: CustomError with Unauthorized message. | ||
### Forbidden(context?) | ||
Return: CustomError with Forbidden message. | ||
### NotFound(context?) | ||
Return: CustomError with Not Found message. | ||
### RequestTimeOut(context?) | ||
Return: CustomError with Request TimeOut message. | ||
### InternalServerError(context?) | ||
Return: CustomError with Internal Server Error message. | ||
### NotImplemented(context?) | ||
Return: CustomError with Not Implemented message. | ||
### CustomError(message, context?) | ||
The CustomError class extends the basic typescript Error class. It is used to create all custom errors. | ||
***Params*** | ||
| Field Name | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| message | string | mandatory | Mandatory error message property | | ||
| context | CustomErrorContext | {} | Optional record of string | | ||
***How to use*** | ||
To create a new error type, export a new const function returning your desired custom error. | ||
````typescript | ||
export const BadRequest = (context?: CustomErrorContext) => | ||
new CustomError('Bad Request', context); | ||
```` | ||
## Tests | ||
@@ -20,0 +71,0 @@ |
/** | ||
* Context is used to pass informal data to the exception, | ||
* We used a string any record to keep the flexibility. | ||
* We used a string record to keep the flexibility. | ||
*/ | ||
@@ -5,0 +5,0 @@ export type CustomErrorContext = Record<string, unknown>; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
26768
5.44%80
175.86%