2.0.4 • Published 2 years ago

typesafe-exception v2.0.4

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Type-safe Exception

Because Error class in JavaScript could have been designed better.

Simple serialization-friendly Exception class, with opt-in type-safe details, numeric status code and custom fields.

Examples

import { Exception } from 'typesafe-exception';

// Sometimes it's handy to put all app errors in `errors.ts`, for better centralization and visibility

// Error `name` will be inferred from class name
export class ValidationError extends Exception {
    // Optionally, numeric `status` can be assigned
    status = 400;
}

// Optionally, `details` field can have types

export class AccessDeniedError extends Exception<{ reason: string }> {
    status = 403;
}

throw new AccessDeniedError('You are not allowed here', { reason: 'too boring' });
2.0.4

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.1

3 years ago

1.0.0

3 years ago