Better Modern Errors for Javascript. Better how? Its Modern Errors but supports CommonJS.
npm install better-modern-errorsBecause modern-errors-commonjs-port was too long
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.
- 🔌 modern-errors README
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.
``js
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')
`
`bash`
pnpm install better-modern-errors
- modern-errors-serialize:
Serialize/parse errors
- modern-errors-clean: Clean
stack traces
- modern-errors-http: Create
HTTP error responses
- modern-errors-winston:
Log errors with Winston
- modern-errors-switch:
Execute class-specific logic
`js``
import {
pluginCleanStack,
pluginHttpResponse,
pluginProcess,
pluginSerialize,
pluginSwitch,
pluginWinston,
} from 'better-modern-errors';