better-modern-errors
v0.1.0
Published
Better Modern Errors for Javascript. Better how? Its Modern Errors but supports CommonJS.
Downloads
50
Readme
better-modern-errors
Why is it better modern errors?
Because modern-errors-commonjs-port was too long
This is blatant copy of Modern Errors. Why?
Because it was in ESM and I needed it in CommonJS. Modern Errors didn't use any of the features of ESM, so I just copied the code out so it could be used in CommonJS. This also required copying all the modules it used that were in ESM too, so all of them are in here as well.
It also includes a handful of the default plugins created by ehmicky for Modern Errors that I thought would be useful for our use case.
See full README for features of Modern Error, all features were included in this copy.
The original library had full test coverage. The tests have been included and migrated to use jest as this was what I was most familiar with and was straightforward to get working with the code being moved to Typescript.
Example
import { BetterError } from 'better-modern-errors'
export const BaseError = BetterError.subclass('BaseError')
export const UnknownError = BaseError.subclass('UnknownError')
export const InputError = BaseError.subclass('InputError')
export const AuthError = BaseError.subclass('AuthError')
export const DatabaseError = BaseError.subclass('DatabaseError')
Install
pnpm install better-modern-errors
Plugins included
modern-errors-serialize
: Serialize/parse errorsmodern-errors-clean
: Clean stack tracesmodern-errors-http
: Create HTTP error responsesmodern-errors-winston
: Log errors with Winstonmodern-errors-switch
: Execute class-specific logic
import {
pluginCleanStack,
pluginHttpResponse,
pluginProcess,
pluginSerialize,
pluginSwitch,
pluginWinston,
} from 'better-modern-errors';