@keq-request/exception 5.0.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,97 @@
1
+ # Changelog
2
+
3
+ ## 5.0.0-alpha.7
4
+
5
+ ### Major Changes
6
+
7
+ - 5175097: **BREAKING CHANGE:** group all packages under the @keq-request scope
8
+
9
+ - keq-cache => @keq-request/cache
10
+ - keq-headers => @keq-request/headers
11
+ - keq-cli => @keq-request/cli
12
+ - keq-url => @keq-request/url
13
+ - keq-exception => @keq-request/exception
14
+
15
+ - 153244f: **BREAKING CHANGE:** move `RequestException` form `@keq-request/exception` to `keq`
16
+
17
+ ### Patch Changes
18
+
19
+ - 153244f: remove override `retryOn`.
20
+ - Updated dependencies [153244f]
21
+ - Updated dependencies [153244f]
22
+ - Updated dependencies [153244f]
23
+ - Updated dependencies [153244f]
24
+ - Updated dependencies [153244f]
25
+ - Updated dependencies [7ff2162]
26
+ - Updated dependencies [153244f]
27
+ - Updated dependencies [153244f]
28
+ - Updated dependencies [153244f]
29
+ - Updated dependencies [153244f]
30
+ - Updated dependencies [153244f]
31
+ - keq@5.0.0-alpha.7
32
+
33
+ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
34
+
35
+ ## [3.2.0](https://github.com/keq-request/keq-exception/compare/v3.1.4...v3.2.0) (2025-06-05)
36
+
37
+ ### Features
38
+
39
+ - add type-fest dependency and update Promisable type usage in catchException and throwException ([7c3cc96](https://github.com/keq-request/keq-exception/commit/7c3cc96a149914afac090ada383010fa4482c311))
40
+
41
+ ## [3.1.4](https://github.com/keq-request/keq-exception/compare/v3.1.3...v3.1.4) (2025-06-05)
42
+
43
+ ### Bug Fixes
44
+
45
+ - update catchException handler to support async functions ([18dd4f2](https://github.com/keq-request/keq-exception/commit/18dd4f25201c9e8eaaa20782b94bc78906807262))
46
+
47
+ ## [3.1.3](https://github.com/keq-request/keq-exception/compare/v3.1.2...v3.1.3) (2024-12-18)
48
+
49
+ ### Bug Fixes
50
+
51
+ - update module exports to include file extensions for esm ([ba42c19](https://github.com/keq-request/keq-exception/commit/ba42c198fe75c2fdd8ad4b6325675fe7920cf45b))
52
+
53
+ ## [3.1.2](https://github.com/keq-request/keq-exception/compare/v3.1.1...v3.1.2) (2024-10-15)
54
+
55
+ ### Bug Fixes
56
+
57
+ - move jest-environment-jsdom to dev deps ([7b316de](https://github.com/keq-request/keq-exception/commit/7b316de1c7720d2f68fb7c63002a595e6cf93798))
58
+
59
+ ## [3.1.1](https://github.com/keq-request/keq-exception/compare/v3.1.0...v3.1.1) (2024-10-15)
60
+
61
+ ### Bug Fixes
62
+
63
+ - export esm module error ([aba0c00](https://github.com/keq-request/keq-exception/commit/aba0c00cc3f0918aa49df8ccfc312b890ee3efa1))
64
+
65
+ ## [3.1.0](https://github.com/keq-request/keq-exception/compare/v3.0.0...v3.1.0) (2024-05-28)
66
+
67
+ ### Features
68
+
69
+ - control whether to trigger retry ([decd756](https://github.com/keq-request/keq-exception/commit/decd756ff54697754ac1e9d9dad97300c824732d))
70
+
71
+ ## [3.0.0](https://github.com/keq-request/keq-exception/compare/v2.1.2...v3.0.0) (2024-05-26)
72
+
73
+ ### ⚠ BREAKING CHANGES
74
+
75
+ - throwException parameter changes
76
+
77
+ ### Features
78
+
79
+ - throw error takes effect when retrying ([5ff1fb5](https://github.com/keq-request/keq-exception/commit/5ff1fb5b3ebca23e63111bb7ace9030da0d2d078))
80
+
81
+ ## [2.1.2](https://github.com/keq-request/keq-exception/compare/v2.1.1...v2.1.2) (2024-05-13)
82
+
83
+ ### Continuous Integration
84
+
85
+ - cannot publish ([3dd7c23](https://github.com/keq-request/keq-exception/commit/3dd7c23aaaa933c03ad8f4634ee888871028e88a))
86
+
87
+ ## [2.1.1](https://github.com/keq-request/keq-exception/compare/v2.1.0...v2.1.1) (2024-05-13)
88
+
89
+ ### Performance Improvements
90
+
91
+ - add middleware function name ([028a50a](https://github.com/keq-request/keq-exception/commit/028a50a54440b303ca1d5f928045ca2fed9bf368))
92
+
93
+ ## [2.1.0](https://github.com/keq-request/keq-exception/compare/v2.0.0...v2.1.0) (2024-04-23)
94
+
95
+ ### Features
96
+
97
+ - message never required for RequestException ([828f29e](https://github.com/keq-request/keq-exception/commit/828f29e8b2048536e1267f45f6380c384ca2afbe))
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Val.istar.Guo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,63 @@
1
+ <!-- title -->
2
+ <p align="center" style="padding-top: 41px">
3
+ <img src="https://raw.githubusercontent.com/keq-request/keq/refs/heads/master/images/logo.svg" width="121" alt="logo" />
4
+ </p>
5
+
6
+ <h2 align="center" style="text-align: center">KEQ-EXCEPTION</h2>
7
+ <!-- title -->
8
+
9
+ [![version](https://img.shields.io/npm/v/keq-exception.svg?style=for-the-badge)](https://www.npmjs.com/package/keq-exception)
10
+ [![downloads](https://img.shields.io/npm/dm/keq-exception.svg?style=for-the-badge)](https://www.npmjs.com/package/keq-exception)
11
+ [![license](https://img.shields.io/npm/l/keq-exception.svg?style=for-the-badge)](https://www.npmjs.com/package/keq-exception)
12
+ [![dependencies](https://img.shields.io/librariesio/release/npm/keq-exception?style=for-the-badge)](https://www.npmjs.com/package/keq-exception)
13
+ [![codecov](https://img.shields.io/codecov/c/gh/keq-request/keq-exception?logo=codecov&token=HWP4GTMWV8&style=for-the-badge)](https://codecov.io/gh/keq-request/keq-exception)
14
+
15
+ [Document EN]: https://keq-request.github.io/guide/libraries/keq-exception
16
+ [Document CN]: https://keq-request.github.io/zh/guide/libraries/keq-exception
17
+
18
+ [**Document**][Document EN] | [**中文文档**][Document CN]
19
+
20
+ `Middleware` for throwing/catching exceptions. And it can control whether the exception trigger `retry`.
21
+
22
+ ## Usage
23
+
24
+ <!-- prettier-ignore -->
25
+ ```typescript
26
+ import { request } from "keq"
27
+ import {
28
+ throwException,
29
+ catchException,
30
+ RequestException,
31
+ } from "keq-exception"
32
+
33
+ request
34
+ .use(
35
+ catchException((err) => {
36
+ if (err instanceof RequestException && err.code === 401) {
37
+ context.redirect("/login")
38
+ return
39
+ }
40
+
41
+ throw err
42
+ })
43
+ )
44
+
45
+ // Callback will run after `await next()`.
46
+ // This way you can throw errors based on the response body.
47
+ .use(
48
+ throwException(async (ctx) => {
49
+ if (ctx.response && ctx.response.status >= 400) {
50
+ const body = await ctx.response.json()
51
+ throw new RequestException(ctx.response.status, body.message)
52
+ }
53
+ })
54
+ )
55
+ ```
56
+
57
+ ### RequestException(statusCode[, errorMessage[, retry]])
58
+
59
+ | **Parameter** | **Default** | **Description** |
60
+ | :------------ | :---------- | -------------------------------------------- |
61
+ | statusCode | - | Error code |
62
+ | message | `''` | Error message |
63
+ | retry | `true` | Whether the thrown error can trigger a retry |
@@ -0,0 +1,14 @@
1
+ import type { Config } from 'jest'
2
+ import { pathsToModuleNameMapper } from 'ts-jest'
3
+ import { compilerOptions } from './tsconfig.json'
4
+
5
+
6
+ export default async (): Promise<Config> => ({
7
+ preset: 'ts-jest',
8
+ // setupFilesAfterEnv: ['<rootDir>/__tests__/setup.ts'],
9
+ moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/src', useESM: true }),
10
+ testMatch: [
11
+ '<rootDir>/__tests__/**/*.spec.ts',
12
+ '<rootDir>/src/**/*.spec.ts',
13
+ ],
14
+ })
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@keq-request/exception",
3
+ "version": "5.0.0-alpha.7",
4
+ "description": "Request exception for keq",
5
+ "keywords": [
6
+ "keq",
7
+ "request",
8
+ "exception",
9
+ "error",
10
+ "fetch"
11
+ ],
12
+ "homepage": "https://github.com/keq-request/keq#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/keq-request/keq/issues"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/keq-request/keq.git"
19
+ },
20
+ "license": "MIT",
21
+ "author": "Val.istar.Guo <val.istar.guo@gmail.com>",
22
+ "types": "dist/index.d.ts",
23
+ "main": "dist/index.js",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "require": "./dist/index.js",
28
+ "import": "./dist/index.mjs"
29
+ }
30
+ },
31
+ "dependencies": {
32
+ "type-fest": "^5.2.0"
33
+ },
34
+ "devDependencies": {
35
+ "@types/node": "^20.19.24",
36
+ "keq": "5.0.0-alpha.7",
37
+ "@keq-request/test": "5.0.0-alpha.7"
38
+ },
39
+ "peerDependencies": {
40
+ "keq": "^5.0.0-alpha.7"
41
+ },
42
+ "scripts": {
43
+ "build": "tsup",
44
+ "dev": "tsup --watch",
45
+ "test": "jest",
46
+ "test:update": "jest -u"
47
+ }
48
+ }