0.0.1 • Published 6 years ago
@booster-ts/error-module v0.0.1
ErrorModule
An Error Module for Booster-TS.
Getting Started
Installation
$ npm i @booster-ts/error-moduleSetting Up
In you project package.json you will need to add the field error-module in the field booster
"booster": {
"error-module": "config_file.json"
}Error Config File
In the config JSON file, you will be able to declare all your errors.
{
"00": {
"why": "No Error"
},
"01": {
"why": "User already exists"
}
}Your error should contain the field why, that explains why the error occures, you can then add custom fields.
Creating an error
The ErrorModule, can be injected directly in your class
import { ErrorModule } from '@booster-ts/error-module';
export class User {
constructor(
private error: ErrorModule
) { }
public createUser(email: string): Promise<void> {
return Promise.reject(this.error.createError("00", "User"))
}
}You will then receive the error in your catch handler as an ErrorContent
interface ErrorContent {
why: string;
from: string;
systemError?: any;
}If you specified custom fields in your config JSON they will be present too.
createError
public createError(code: string, from: string = "", systemError: any = null): ErrorContent;In the method createError you can specify where the error occured from and add the stack trace systemError