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

1.5.0 • Public • Published

@belgattitude/http-exception

Warning ⚠️ This package have been moved to https://github.com/belgattitude/httpx ⚠️

No breaking changes, just update from @belgattitude/http-exception to @httpx/exception.

Delightful http exceptions. Crafted with node, browsers, ssr frameworks and error logging in mind.

npm size node browserslist dist ci codecov techdebt maintainability license

Highlights

Documentation

👉 See full documentation on https://belgattitude.github.io/http-exception. 👈

Install

npm install @belgattitude/http-exception  # via npm
yarn add @belgattitude/http-exception     # via yarn

Quick start

Simple named exceptions:

import {
  HttpGatewayTimeout,
  HttpInternalServerError,
  HttpNotFound,
  HttpServiceUnavailable,
} from "@belgattitude/http-exception";

throw new HttpNotFound(); // message = 'Not found', statusCode = 404

// Custom message
throw new HttpServiceUnavailable("Service temporarily unavailable");

// Custom context
throw new HttpInternalServerError({
  message: "Oups, this is on our side.",
  url: "https://api.dev/gateway",
  code: "EXTERNAL_SERVICE_TIMEOUT",
  cause: new HttpGatewayTimeout({
    code: "This Serverless Function has timed out",
    errorId: "cdg1::h99k2-1664884491087-b41a2832f559",
  }),
});

By status code

import { createHttpException } from "@belgattitude/http-exception";

const e404 = createHttpException(404);
const e500 = createHttpException(500, { message: "Server error" });

Serialization

import { fromJson, toJson } from "@belgattitude/http-exception/serializer";

const e = new HttpForbidden();

const json = toJson(e);
const deserialized = fromJson(json);

More in the docs: https://belgattitude.github.io/http-exception

Support

Don't hesitate and open an issue.

Contributors

Contributors are warmly welcomed. Have a look to the CONTRIBUTING document.

Sponsors

If you are enjoying some of my OSS guides or libs for your company, I'd really appreciate a sponsorship, a coffee or a dropped star. That gives me a tasty morning boost and help me to make some of my ideas come true 🙏

License

MIT

Package Sidebar

Install

npm i @belgattitude/http-exception

Weekly Downloads

222

Version

1.5.0

License

MIT

Unpacked Size

149 kB

Total Files

70

Last publish

Collaborators

  • s.vanvelthem