human-errors
v1.1.4
Published
Human friendly errors for your APIs & projects.
Downloads
4
Maintainers
Readme
A tiny error handling library to make your API's more human friendly. Inspired by Stripe's API
human-errors
is a tiny error handling library with the purpose of building more human-friendly and helpful API errors and responses. Inspired greatly by the amazing API design of Stripe.
Features
- Associate all logs with a user
Usage
import { createHumanErrors } from 'human-errors'
const errors = {
// this is your api error code
parameter_unknown: {
doc_url: 'https://stripe.com/docs/error-codes/parameter-unknown',
message: {
template: 'Received unknown parameter: {{missingParameter}}',
params: {
unknownParam: 'hello'
}
},
param: 'hello',
status_code: 400,
type: 'invalid_request_error'
}
} as const
const humanError = createHumanError(errors)
console.log(humanError.error('parameter_unknown', { unknownParam: 'page_id' }))
// ^ this is inferred automatically
License
human-errors
is released under the MIT License.
TODO
- Tests for types