@golemio/errors
Advanced tools
Comparing version 2.0.0-dev.877224914 to 2.0.0-dev.877231197
@@ -8,2 +8,4 @@ export interface IGolemioError { | ||
} | ||
export interface ICustomError extends IGolemioError { | ||
} | ||
export declare type IGolemioErrorInfoType = Error | IGolemioErrorInfoObject | IGolemioErrorInfoObject[] | string; | ||
@@ -10,0 +12,0 @@ interface IGolemioErrorInfoObject { |
export * from "./errors/interfaces/GolemioErrorInterface"; | ||
export * from "./errors/AbstractGolemioError"; | ||
export * from "./errors/BusinessError"; | ||
export * from "./errors/CustomError"; | ||
export * from "./errors/DatasourceError"; | ||
export * from "./errors/FatalError"; | ||
export * from "./errors/GeneralError"; | ||
export * from "./errors/UnprocessableError"; | ||
export * from "./errors/RecoverableError"; | ||
export * from "./errors/TransformationError"; | ||
export * from "./errors/ValidationError"; | ||
export * from "./handlers/ErrorHandler"; | ||
export * from "./handlers/HTTPErrorHandler"; |
@@ -20,6 +20,10 @@ "use strict"; | ||
__exportStar(require("./errors/AbstractGolemioError"), exports); | ||
__exportStar(require("./errors/BusinessError"), exports); | ||
__exportStar(require("./errors/CustomError"), exports); | ||
__exportStar(require("./errors/DatasourceError"), exports); | ||
__exportStar(require("./errors/FatalError"), exports); | ||
__exportStar(require("./errors/GeneralError"), exports); | ||
__exportStar(require("./errors/UnprocessableError"), exports); | ||
__exportStar(require("./errors/RecoverableError"), exports); | ||
__exportStar(require("./errors/TransformationError"), exports); | ||
__exportStar(require("./errors/ValidationError"), exports); | ||
/* handlers */ | ||
@@ -26,0 +30,0 @@ __exportStar(require("./handlers/ErrorHandler"), exports); |
{ | ||
"name": "@golemio/errors", | ||
"version": "2.0.0-dev.877224914", | ||
"version": "2.0.0-dev.877231197", | ||
"description": "Library of Error classes of the Golemio Data Platform System", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -46,5 +46,7 @@ # Golemio Errors Library | ||
npm install @golemio/errors --save | ||
``` | ||
or | ||
``` | ||
yarn add @golemio/errors --save | ||
@@ -56,6 +58,6 @@ ``` | ||
``` | ||
import { GeneralError } from "@golemio/errors"; | ||
import { GeneralError, FatalError } from "@golemio/errors"; | ||
``` | ||
Our GeneralError has: | ||
Our AbstractGolemioError has: | ||
@@ -65,12 +67,18 @@ - whole stack trace of original `Error` | ||
- extra info about origin class | ||
- extra info about error code | ||
- distinguishes between operational errors (application error, app knows how to handle it) and fatal errors (app should gracefully die) | ||
- string message (== only thing the native Error has) | ||
- extra info about error status code | ||
- string message (== same as native Error) | ||
You can use GeneralError class as you would a standard JavaScript Error, you will just get additional info and more capabilities: | ||
There are two main classes: `GeneralError` and `FatalError`. Both are extending `AbstractGolemioError` class. Furthermore, `GeneralError` subclasses: | ||
- `BusinessError` | ||
- `DatasourceError` | ||
- `RecoverableError` | ||
- `TransformationError` | ||
- `ValidationError` | ||
You can use instance of AbstractGolemioError class as you would a standard JavaScript Error, you will just get additional info and more capabilities: | ||
``` | ||
const found = await this.model.findOne(id); | ||
if (!found ) { | ||
throw new GeneralError("Id `" + id + "` not found", "MyModelClass", undefined, 404); | ||
throw new GeneralError("Id `" + id + "` not found", "MyModelClass", new Error("More info"), 404); | ||
} | ||
@@ -93,3 +101,3 @@ ``` | ||
``` | ||
"MyModelClass" [500] Database error (ObjectParameterError: Parameter "filter" to find() must be an object, got nonsense) | ||
MyModelClass: [500] Database error (ObjectParameterError: Parameter "filter" to find() must be an object, got nonsense) | ||
GeneralError: Database error | ||
@@ -102,3 +110,3 @@ at MyModel.<anonymous> ({path}\src\core\models\MyModel.ts:65:19) | ||
if you call .toString() on the error object in the error handler (or if you use our ErrorHandler class). | ||
if you call `.toString()` on the error object in the error handler (or if you use our ErrorHandler class). | ||
@@ -111,3 +119,3 @@ You can import the error handler function: | ||
The handle function provides a central point for error handling in your application. It logs the error, kills the application if it's unknown non-operational (programmer) error. Returns "API response ready" object if it's a known operational error with one of the standard HTTP codes. | ||
The handle function provides a central point for error handling in your application. It logs the error, kills the application if it's unknown or fatal (programmer) error. Returns "API response ready" object if it's a known expected error with one of the standard HTTP codes. | ||
@@ -118,3 +126,3 @@ You can use it: | ||
try { | ||
await functionThatThrowsGolemioError(); // Can throw our GolemioError class | ||
await functionThatThrowsError(); // Can throw our Error class | ||
await jsBuiltInFunction(); // Can throw a native built-in JavaScript Error | ||
@@ -156,6 +164,6 @@ } catch (err) { // Catches everything | ||
"error_stack": "GeneralError: Id `nonsense` not found\n | ||
at MyModel.<anonymous> ({path}y\\dist\\core\\models\\MyModel.js:116:23)\n | ||
at Generator.next (<anonymous>)\n | ||
at fulfilled ({path}\\dist\\core\\models\\MyModel.js:4:58)\n | ||
at process._tickCallback (internal/process/next_tick.js:68:7)" | ||
at MyModel.<anonymous> ({path}y\\dist\\core\\models\\MyModel.js:116:23)\n | ||
at Generator.next (<anonymous>)\n | ||
at fulfilled ({path}\\dist\\core\\models\\MyModel.js:4:58)\n | ||
at process._tickCallback (internal/process/next_tick.js:68:7)" | ||
} | ||
@@ -162,0 +170,0 @@ ``` |
Sorry, the diff of this file is not supported yet
36295
42
437
181