@httpie/http-errors
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published


HTTP Errors

An HTTP error class throwing with proper status codes


Installation · Usage



Latest Version Monthly downloads

Follow @eldorplus and @httpiejs for updates!


Introduction

The @httpie/http-errors package provides an HTTP error class with useful defaults.

  • provides an HttpError base class with defaults to throw proper HTTP errors
  • the HttpError base class captures stack traces by default
  • create your own HTTP error with custom HTTP status code, title, and error code

Installation

npm i @httpie/http-errors

Quick Usage Overview

Using @httpie/http-errors is pretty straightforward. The package exports the HttpError class that you can use like the native Error class.

const { HttpError } = require('@httpie/http-errors')

// create an HTTP 400 BadRequest error yourself
throw new HttpError('invalid request input data', 400)

// … or throw using shortcut methods
throw HttpError.badRequest('Request validation failed')

// … or use a fluent interface to customize the properties
throw new HttpError('Request validation failed')
  .withStatus(400)
  .withCode('E_YOUR_CUSTOM_ERROR_CODE')

Contributing

Do you miss a function? We very much appreciate your contribution! Please send in a pull request 😊

  1. Create a fork
  2. Create your feature branch: git checkout -b my-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request 🚀

License

MIT © Supercharge


httpiejs.com  ·  GitHub @httpie  ·  Twitter @httpiejs

Package Sidebar

Install

npm i @httpie/http-errors

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

26 kB

Total Files

8

Last publish

Collaborators

  • eldorplus