human-errors
TypeScript icon, indicating that this package has built-in type declarations

1.1.4 • Public • Published

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

Package Sidebar

Install

npm i human-errors

Weekly Downloads

7

Version

1.1.4

License

MIT

Unpacked Size

21.1 kB

Total Files

6

Last publish

Collaborators

  • skoshx