Skip to content

skoshx/human-errors

Repository files navigation

A tiny error handling library to make your API's more human friendly. Inspired by Stripe's API

license CI prettier PRs Welcome

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

About

🛠 A tiny error handling library to make your API's more human friendly. Inspired by Stripe's API.

Resources

License

Stars

Watchers

Forks

Packages

No packages published