# @belgattitude/http-exception 中文文档

规范地址：https://npmcn.com/package/%40belgattitude/http-exception/

版本：1\.5\.0
npm 元数据更新时间：2022-11-22T09:21:39.709Z
中文译文更新时间：2026-11-07T21:32:17.526Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40belgattitude/http-exception
原文对照：https://npmcn.com/package/%40belgattitude/http-exception/?lang=original
项目主页：https://github.com/belgattitude/http-exception
源码仓库：https://github.com/belgattitude/http-exception

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：149 kB，70 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=14\.16
- 运行依赖：0 个
- 首次发布：2022-09-11T19:12:31.186Z
- 最新版本发布：2022-11-22T09:21:39.510Z
- 近 30 天下载量：7726（2026-10-08 至 2026-11-06，npm 官方下载统计）
- 已发布版本数：26（近 12 个月 0 个）

## 中文简介

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

## 安装

```sh
npm install @belgattitude/http-exception
```

也可以使用：`pnpm add @belgattitude/http-exception`、`yarn add @belgattitude/http-exception`、`bun add @belgattitude/http-exception`

## README

# @belgatitude/http-例外

> **3⁄4 ̄ ̧漯B** ++ 此软件包已移至 [https://github.com/belgattitude/httpx (中文(简体) )](https://github.com/belgattitude/httpx) ⚠️
> 
> 没有中断更改, 只是更新从 `@belgattitude/http-exception` 改为 `@httpx/exception`。 。 。 .

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

[![npm](https://img.shields.io/npm/v/@belgattitude/http-exception?style=for-the-badge&labelColor=222)](https://www.npmjs.com/package/@belgattitude/http-exception) [![size](https://img.shields.io/bundlephobia/minzip/@belgattitude/http-exception@latest?label=MinGZIP&style=for-the-badge&labelColor=333&color=informational)](https://bundlephobia.com/package/@belgattitude/http-exception@latest) [![node](https://img.shields.io/static/v1?label=Node&message=14%2b&logo=node.js&style=for-the-badge&labelColor=444&color=informational)](https://browserslist.dev/?q=PjAuMjUlLCBub3QgZGVhZA%3D%3D) [![browserslist](https://img.shields.io/static/v1?label=Browser&message=%3E0.25%&logo=googlechrome&style=for-the-badge&labelColor=444&color=informational)](https://browserslist.dev/?q=PjAuMjUlLCBub3QgZGVhZA%3D%3D) [![dist](https://img.shields.io/static/v1?label=&message=cjs%7Cesm%7Ctreeshake&logo=webpack&style=for-the-badge&labelColor=444&color=informational)](https://github.com/belgattitude/http-exception/blob/main/packages/http-exception/.size-limit.cjs) [![ci](https://img.shields.io/github/checks-status/belgattitude/http-exception/main?label=CI&logo=github&style=for-the-badge&labelColor=444)](https://github.com/belgattitude/http-exception/actions?query=branch%3Amain) [![codecov](https://img.shields.io/codecov/c/github/belgattitude/http-exception?logo=codecov&style=for-the-badge&labelColor=444)](https://codecov.io/gh/belgattitude/http-exception) [![techdebt](https://img.shields.io/codeclimate/tech-debt/belgattitude/http-exception?label=TechDebt&logo=code-climate&style=for-the-badge&labelColor=444)](https://codeclimate.com/github/belgattitude/http-exception) [![maintainability](https://img.shields.io/codeclimate/maintainability/belgattitude/http-exception?label=Maintainability&logo=code-climate&style=for-the-badge&labelColor=444)](https://codeclimate.com/github/belgattitude/http-exception) [![license](https://img.shields.io/npm/l/@belgattitude/http-exception?style=for-the-badge&labelColor=000000)](https://github.com/belgattitude/http-exception/blob/main/LICENSE)

## 要点

-   很简单: [明确命名的进口](https://belgattitude.github.io/http-exception/#/?id=named-exceptions) 和(或) [状态代码](https://belgattitude.github.io/http-exception/#/?id=factories)。 。 。 .
-   QQ 到处工作:节点,浏览器,边缘... 框架不可知,没有道克.
-   与乐格友好 [上下文](https://belgattitude.github.io/http-exception/#/?id=about-context) 信息输入。 少猜游戏.
-   🐎  [可序列](https://belgattitude.github.io/http-exception/#/?id=serializer) 以覆盖 Server-Side-Rendering 使用大小写(nextjs, superjson,...).
-   达到标准. [扩展](https://belgattitude.github.io/http-exception/#/?id=uml-class-diagram) 错误分类 [堆栈](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/stack) 财务报告和审定财务报表 [错误。 因为](https://belgattitude.github.io/http-exception/#/?id=about-errorcause) 支助.
-   🍃  [轻巧](https://bundlephobia.com/package/@belgattitude/http-exception@latest) - 说吧 [可动摇的树](https://github.com/belgattitude/http-exception/blob/main/packages/http-exception/.size-limit.cjs) - 宽 [浏览器覆盖](https://browserslist.dev/?q=PjAuMjUlLCBub3QgZGVhZA%3D%3D) (取舍).
-   默认状态图文集为 [错误消息](https://belgattitude.github.io/http-exception/#/?id=about-default-message)更少的字符,差异...
-   (原始内容存档于2018-10-25). QQ IDE Friendly. Typescript - 有mdn和描述链接的tivedoc.
-   🥃  [文档](https://belgattitude.github.io/http-exception) 打开 [更改日志](https://github.com/belgattitude/http-exception/releases) - 测试和保养良好 [贡献者](https://github.com/belgattitude/http-exception/blob/main/CONTRIBUTING.md) 欢迎.

## 文档

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

## 安装

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

## 快开始

简单的命名例外 :

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

按状态代码

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

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

序列化

```typescript
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 页面存档备份,存于互联网档案馆](https://belgattitude.github.io/http-exception)

## 支助

不要犹豫和打开 [问题](https://github.com/belgattitude/http-exception/issues)。 。 。 .

## 贡献者

贡献者受到热烈欢迎。 来看看 [捐款](https://github.com/belgattitude/http-exception/blob/main/CONTRIBUTING.md) 文档.

## 赞助者

如果你喜欢我的一些OSS指南 或为你的公司,我真的很感谢 [赞助](https://github.com/sponsors/belgattitude)页:1 [咖啡业](https://ko-fi.com/belgattitude) 或者是掉下来的星星 这给了我一个美味的早晨助推 并帮助我 让我的一些想法成真

## 许可证

麻省理工学院

## 常见问题

### @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 和提交记录判断。

