@belgattitude/http-exception

中文文档
1.5.0发布于 2022/11/22MITTypeScriptESM + CJS零依赖近 30 天下载 7726

Warning: has been moved to @httpx/exception. Please update.

原始使用文档
文档目录8 节
  1. Highlights
  2. Documentation
  3. Install
  4. Quick start
  5. Support
  6. Contributors
  7. Sponsors ♥
  8. License

@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

版本与发布记录

@belgattitude/http-exception 共发布 26 个版本,首次发布于 2022/09/12;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.5.0latest2022/11/223 年前
1.4.02022/10/214 年前
1.3.42022/10/124 年前
1.3.32022/10/054 年前
1.3.22022/10/034 年前
1.3.12022/10/014 年前

其他发布通道:canary → 0.1.10-canary.1。

关于 @belgattitude/http-exception 的常见问题

@belgattitude/http-exception 是什么?

Warning: has been moved to @httpx/exception. Please update.

如何安装 @belgattitude/http-exception?

在项目目录运行 npm install @belgattitude/http-exception,或使用 pnpm add / yarn add / bun add。

@belgattitude/http-exception 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@belgattitude/http-exception 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@belgattitude/http-exception 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=14.16。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@belgattitude/http-exception 可以商用吗?

@belgattitude/http-exception 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@belgattitude/http-exception 的下载量有多少?

根据 npm 官方下载统计,@belgattitude/http-exception 在 2026/10/08 – 2026/11/06 这 30 天内被下载 7,726 次,日均约 258 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@belgattitude/http-exception 还在维护吗?

最新版本 1.5.0 发布于 2022/11/22(3 年前);至今共发布 26 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/09/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。