2.0.1 • Published 6 months ago

@onibi/errors v2.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
6 months ago

@onibi/errors

Standardized error types for most common HTTP error status codes that have a built-in .toJSON method that converts the error into a standardized JSON response. Best used in conjunction with the @onibi/errorhandler for express.js that automatically catches any HttpError and returns correct status code/JSON response.

JSON response

All errors contain a .toJSON method that converts the error into a standardized JSON response according to the interface below:

interface ApiErrorResponse {
    /** HTTP status code. */
    statusCode: number;

    /** Unique type id for this error type. */
    errorType: string;

    /** Generic name for this error type, may be shown to end users. */
    errorName: string;

    /** Error description for programmers/debugging, should NOT be shown to end users. */
    description: string;

    /** Error message that describes the error in more detail, may be shown to end users. */
    message: string;

    /** Error message is safe to show to users/user friendly. */
    isUserSafe: boolean;

    /** Stack trace for the error, must be explicitly added by the error handler and should never be populated in production environments. */
    stackTrace?: string;
}

Usage example

import express from 'express';
import { Http404Error } from '@onibi/errors';
import errorHandler from '@onibi/errorhandler';

let app = express();

app.get('/404', (req, res) => {
    throw new Http404Error();
})

// The errorHandler should always be the last thing added to the express app.
app.user(errorHandler);

app.listen(8080);
0.1.12

11 months ago

0.1.13

11 months ago

0.1.14

11 months ago

2.0.1

6 months ago

2.0.0

6 months ago

0.1.10

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.0

2 years ago