@@ -49,3 +49,70 @@ request
4949| statusCode | - | 错误码 |
5050| message | ` '' ` | 错误信息 |
5151| retry | ` true ` | 异常是否会触发` retry ` |
52+
53+ ## Middleware
54+
55+ ### validateStatusCode
56+
57+ 验证 ` Response ` 的 ` status ` ,并抛出对应的 ` RequestException ` :
58+
59+ - ` status ` 在 ` 200-399 ` 范围内时,不抛出异常
60+ - ` status = 400 ` 时,抛出 ` BadRequestException(statusText) `
61+ - ` status = 401 ` 时,抛出 ` UnauthorizedException(statusText) `
62+ - ` status = 403 ` 时,抛出 ` ForbiddenException(statusText) `
63+ - ` status = 404 ` 时,抛出 ` NotFoundException(statusText) `
64+ - ` status = 405 ` 时,抛出 ` MethodNotAllowedException(statusText) `
65+ - ` status = 406 ` 时,抛出 ` NotAcceptableException(statusText) `
66+ - ` status = 407 ` 时,抛出 ` ProxyAuthenticationRequiredException(statusText) `
67+ - ` status = 408 ` 时,抛出 ` RequestTimeoutException(statusText) `
68+ - ` status = 409 ` 时,抛出 ` ConflictException(statusText) `
69+ - ` status = 412 ` 时,抛出 ` PreconditionFailedException(statusText) `
70+ - ` status = 413 ` 时,抛出 ` ContentTooLargeException(statusText) `
71+ - ` status = 414 ` 时,抛出 ` UriTooLongException(statusText) `
72+ - ` status = 415 ` 时,抛出 ` UnsupportedMediaTypeException(statusText) `
73+ - ` status = 418 ` 时,抛出 ` ImATeapotException(statusText) `
74+ - ` status = 429 ` 时,抛出 ` TooManyRequestsException(statusText) `
75+ - ` status ` 为其他 ` 400-499 ` 的数值时,抛出 ` RequestException(status, statusText, false) `
76+ - ` status = 500 ` 时,抛出 `InternalServerErrorException(statusText
77+ - ` status = 501 ` 时,抛出 ` NotImplementedException(statusText) `
78+ - ` status = 502 ` 时,抛出 ` BadGatewayException(statusText) `
79+ - ` status = 503 ` 时,抛出 ` ServiceUnavailableException(statusText) `
80+ - ` status = 504 ` 时,抛出 ` GatewayTimeoutException(statusText) `
81+ - ` status ` 为其他 ` 500-599 ` 的数值时,抛出 ` RequestException(status, statusText, true) `
82+
83+ ** 示例**
84+
85+ ``` typescript
86+ import { request } from " keq"
87+ import { validateStatusCode } from " @keq-request/exception"
88+
89+ request .use (validateStatusCode ())
90+ ```
91+
92+ ## Plugin
93+
94+ ### ValidateStatusCode
95+
96+ 用于 ` @keq-request/cli ` 的 Plugin,其主要功能有:
97+
98+ 1 . 删除 ` openapi ` / ` swagger ` 文档中的异常响应定义
99+ 2 . 添加 ` validateStatusCode ` Middleware
100+
101+ ** Options**
102+
103+ | ** 参数** | ** 是否必填** | ** 类型** | ** 默认值** | ** 描述** |
104+ | :------- | :----------- | :------- | :--------- | ---------------------- |
105+ | modules | 否 | string[ ] | ` undefined ` | 生效的 ` module ` 名称列表 |
106+
107+ ** 示例**
108+
109+ ``` typescript title=".keqrc.ts"
110+ import { DefineKeqConfig } from " @keq-request/cli"
111+ import { ValidateStatusCode } from " @keq-request/exception/plugins"
112+
113+ const config: DefineKeqConfig = {
114+ // ...
115+ plugins: [
116+ new ValidateStatusCode (/* { modules: [...] } */ )
117+ ],
118+ }
0 commit comments