@golemio/errors
Advanced tools
Comparing version 1.0.3-dev.707838763 to 1.0.3-dev.751881874
{ | ||
"name": "@golemio/errors", | ||
"version": "1.0.3-dev.707838763", | ||
"version": "1.0.3-dev.751881874", | ||
"description": "Library of Error classes of the Golemio Data Platform System", | ||
@@ -12,4 +12,4 @@ "main": "dist/index.js", | ||
"test": "cross-env NODE_ENV=test TS_NODE_COMPILER='ttypescript' mocha --exit --check-leaks --timeout 120000 -r ts-node/register -r dotenv/config 'test/**/*.test.ts'", | ||
"test-debug": "run-s 'test --inspect-brk=9230'", | ||
"code-coverage": "nyc run-s 'test -r source-map-support/register'", | ||
"test-debug": "run-s 'test -- --inspect-brk=9230'", | ||
"code-coverage": "nyc run-s 'test -- -r source-map-support/register'", | ||
"lint": "tslint -p .", | ||
@@ -25,2 +25,6 @@ "generate-docs": "typedoc --out docs/typedoc src" | ||
}, | ||
"engines": { | ||
"node": ">=16.0.0", | ||
"npm": ">=8.0.0" | ||
}, | ||
"devDependencies": { | ||
@@ -27,0 +31,0 @@ "@types/chai": "^4.2.14", |
@@ -9,7 +9,5 @@ # Golemio Errors Library | ||
## Prerequisites | ||
- node.js (https://nodejs.org) | ||
- yarn (https://yarnpkg.com) | ||
- TypeScript (https://www.typescriptlang.org/) | ||
@@ -22,4 +20,5 @@ | ||
Install all npm modules using command: | ||
``` | ||
yarn | ||
npm install | ||
``` | ||
@@ -32,14 +31,17 @@ | ||
``` | ||
yarn run build | ||
npm run build | ||
``` | ||
or run this, to watch all changes | ||
``` | ||
yarn run build-watch | ||
npm run build-watch | ||
``` | ||
from the application's root directory. | ||
## Usage | ||
In your project's `package.json` set dependency to Errors | ||
``` | ||
@@ -54,2 +56,3 @@ npm install @golemio/errors --save | ||
Then import module, e.g. | ||
``` | ||
@@ -68,3 +71,2 @@ import { CustomError } from "@golemio/errors"; | ||
You can use CustomError class as you would a standard JavaScript Error, you will just get additional info and more capabilities: | ||
@@ -80,2 +82,3 @@ | ||
you can add the underlying Error to get the whole stack trace: | ||
``` | ||
@@ -91,2 +94,3 @@ try { | ||
and the result you will get: | ||
``` | ||
@@ -108,2 +112,3 @@ "MyModelClass" [500] Database error (ObjectParameterError: Parameter "filter" to find() must be an object, got nonsense) | ||
``` | ||
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. | ||
@@ -123,2 +128,3 @@ | ||
or for example in Express error handler route | ||
``` | ||
@@ -137,2 +143,3 @@ // Error handler to catch all errors sent by routers (propagated through next(err)) | ||
and the result can be i.e.: | ||
``` | ||
@@ -144,3 +151,5 @@ { | ||
``` | ||
or in development environment (NODE_ENV set to "development"): | ||
``` | ||
@@ -166,3 +175,3 @@ { | ||
For generating documentation run `yarn run generate-docs`. TypeDoc source code documentation is located in `docs/typedoc`. | ||
For generating documentation run `npm run generate-docs`. TypeDoc source code documentation is located in `docs/typedoc`. | ||
@@ -169,0 +178,0 @@ ## Contribution guidelines |
34972
173