@belgattitude/http-exception

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

警告: 已被移动到 @ httpx/ 例外 。 请更新.

中文使用文档
文档目录8 节
  1. 要点
  2. 文档
  3. 安装
  4. 快开始
  5. 支助
  6. 贡献者
  7. 赞助者
  8. 许可证

@belgatitude/http-例外

3⁄4 ̄ ̧漯B ++ 此软件包已移至 https://github.com/belgattitude/httpx (中文(简体) ) ⚠️

没有中断更改, 只是更新从 @belgattitude/http-exception 改为 @httpx/exception。 。 。 .

愉快的 http 例外 。 以节点、浏览器、 sr 框架和错误记录来计算.

npm size node browserslist dist ci codecov techdebt maintainability license

要点

文档

👉 见关于 https://belgattitude.github.io/http-unition 页面存档备份,存于互联网档案馆。 。 。

安装

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

快开始

简单的命名例外 :

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",
  }),
});

按状态代码

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

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

序列化

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

const e = new HttpForbidden();

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

更多文件显示: https://belgattitude.github.io/http-unition 页面存档备份,存于互联网档案馆

支助

不要犹豫和打开 问题。 。 。 .

贡献者

贡献者受到热烈欢迎。 来看看 捐款 文档.

赞助者

如果你喜欢我的一些OSS指南 或为你的公司,我真的很感谢 赞助页:1 咖啡业 或者是掉下来的星星 这给了我一个美味的早晨助推 并帮助我 让我的一些想法成真

许可证

麻省理工学院

版本与发布记录

@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 是什么?

警告: 已被移动到 @ httpx/ 例外 。 请更新.

如何安装 @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 和提交记录判断。