1.1.4 • Published 1 year ago

human-errors v1.1.4

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

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
1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago