New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

human-errors

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

human-errors

Human friendly errors for your APIs & projects.

latest
npmnpm
Version
1.1.4
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

typescript

FAQs

Package last updated on 22 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts