@keq-request/exception 5.0.0-alpha.10

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,125 @@
1
+ # Changelog
2
+
3
+ ## 5.0.0-alpha.10
4
+
5
+ ### Patch Changes
6
+
7
+ - e7eb9dc: Don't publish .turbo and jest.config.cts to npm
8
+ - 7343445: Incorrect build before release
9
+ - Updated dependencies [e7eb9dc]
10
+ - Updated dependencies [7343445]
11
+ - keq@5.0.0-alpha.10
12
+
13
+ ## 5.0.0-alpha.9
14
+
15
+ ### Patch Changes
16
+
17
+ - 2686b8d: build with burbo
18
+ - 2686b8d: remove private dependencies
19
+ - Updated dependencies [2686b8d]
20
+ - Updated dependencies [2686b8d]
21
+ - keq@5.0.0-alpha.9
22
+
23
+ ## 5.0.0-alpha.8
24
+
25
+ ### Patch Changes
26
+
27
+ - 0873c7e: Incorrect build before release.
28
+ - Updated dependencies [0873c7e]
29
+ - keq@5.0.0-alpha.8
30
+
31
+ ## 5.0.0-alpha.7
32
+
33
+ ### Major Changes
34
+
35
+ - 5175097: **BREAKING CHANGE:** group all packages under the @keq-request scope
36
+
37
+ - keq-cache => @keq-request/cache
38
+ - keq-headers => @keq-request/headers
39
+ - keq-cli => @keq-request/cli
40
+ - keq-url => @keq-request/url
41
+ - keq-exception => @keq-request/exception
42
+
43
+ - 153244f: **BREAKING CHANGE:** move `RequestException` form `@keq-request/exception` to `keq`
44
+
45
+ ### Patch Changes
46
+
47
+ - 153244f: remove override `retryOn`.
48
+ - Updated dependencies [153244f]
49
+ - Updated dependencies [153244f]
50
+ - Updated dependencies [153244f]
51
+ - Updated dependencies [153244f]
52
+ - Updated dependencies [153244f]
53
+ - Updated dependencies [7ff2162]
54
+ - Updated dependencies [153244f]
55
+ - Updated dependencies [153244f]
56
+ - Updated dependencies [153244f]
57
+ - Updated dependencies [153244f]
58
+ - Updated dependencies [153244f]
59
+ - keq@5.0.0-alpha.7
60
+
61
+ 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.
62
+
63
+ ## [3.2.0](https://github.com/keq-request/keq-exception/compare/v3.1.4...v3.2.0) (2025-06-05)
64
+
65
+ ### Features
66
+
67
+ - add type-fest dependency and update Promisable type usage in catchException and throwException ([7c3cc96](https://github.com/keq-request/keq-exception/commit/7c3cc96a149914afac090ada383010fa4482c311))
68
+
69
+ ## [3.1.4](https://github.com/keq-request/keq-exception/compare/v3.1.3...v3.1.4) (2025-06-05)
70
+
71
+ ### Bug Fixes
72
+
73
+ - update catchException handler to support async functions ([18dd4f2](https://github.com/keq-request/keq-exception/commit/18dd4f25201c9e8eaaa20782b94bc78906807262))
74
+
75
+ ## [3.1.3](https://github.com/keq-request/keq-exception/compare/v3.1.2...v3.1.3) (2024-12-18)
76
+
77
+ ### Bug Fixes
78
+
79
+ - update module exports to include file extensions for esm ([ba42c19](https://github.com/keq-request/keq-exception/commit/ba42c198fe75c2fdd8ad4b6325675fe7920cf45b))
80
+
81
+ ## [3.1.2](https://github.com/keq-request/keq-exception/compare/v3.1.1...v3.1.2) (2024-10-15)
82
+
83
+ ### Bug Fixes
84
+
85
+ - move jest-environment-jsdom to dev deps ([7b316de](https://github.com/keq-request/keq-exception/commit/7b316de1c7720d2f68fb7c63002a595e6cf93798))
86
+
87
+ ## [3.1.1](https://github.com/keq-request/keq-exception/compare/v3.1.0...v3.1.1) (2024-10-15)
88
+
89
+ ### Bug Fixes
90
+
91
+ - export esm module error ([aba0c00](https://github.com/keq-request/keq-exception/commit/aba0c00cc3f0918aa49df8ccfc312b890ee3efa1))
92
+
93
+ ## [3.1.0](https://github.com/keq-request/keq-exception/compare/v3.0.0...v3.1.0) (2024-05-28)
94
+
95
+ ### Features
96
+
97
+ - control whether to trigger retry ([decd756](https://github.com/keq-request/keq-exception/commit/decd756ff54697754ac1e9d9dad97300c824732d))
98
+
99
+ ## [3.0.0](https://github.com/keq-request/keq-exception/compare/v2.1.2...v3.0.0) (2024-05-26)
100
+
101
+ ### ⚠ BREAKING CHANGES
102
+
103
+ - throwException parameter changes
104
+
105
+ ### Features
106
+
107
+ - throw error takes effect when retrying ([5ff1fb5](https://github.com/keq-request/keq-exception/commit/5ff1fb5b3ebca23e63111bb7ace9030da0d2d078))
108
+
109
+ ## [2.1.2](https://github.com/keq-request/keq-exception/compare/v2.1.1...v2.1.2) (2024-05-13)
110
+
111
+ ### Continuous Integration
112
+
113
+ - cannot publish ([3dd7c23](https://github.com/keq-request/keq-exception/commit/3dd7c23aaaa933c03ad8f4634ee888871028e88a))
114
+
115
+ ## [2.1.1](https://github.com/keq-request/keq-exception/compare/v2.1.0...v2.1.1) (2024-05-13)
116
+
117
+ ### Performance Improvements
118
+
119
+ - add middleware function name ([028a50a](https://github.com/keq-request/keq-exception/commit/028a50a54440b303ca1d5f928045ca2fed9bf368))
120
+
121
+ ## [2.1.0](https://github.com/keq-request/keq-exception/compare/v2.0.0...v2.1.0) (2024-04-23)
122
+
123
+ ### Features
124
+
125
+ - 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,4 @@
1
+ import { KeqMiddleware } from 'keq';
2
+ import { Promisable } from 'type-fest';
3
+ export declare function catchException(handler: (e: unknown) => Promisable<void>): KeqMiddleware;
4
+ //# sourceMappingURL=catch-exception.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catch-exception.d.ts","sourceRoot":"","sources":["../src/catch-exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAA;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAGtC,wBAAgB,cAAc,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,UAAU,CAAC,IAAI,CAAC,GAAG,aAAa,CAQvF"}
@@ -0,0 +1,3 @@
1
+ export * from './throw-exception.js';
2
+ export * from './catch-exception.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ catchException: () => catchException,
24
+ throwException: () => throwException
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+
28
+ // src/throw-exception.ts
29
+ function throwException(check) {
30
+ return async function throwException2(ctx, next) {
31
+ await next();
32
+ await check(ctx);
33
+ };
34
+ }
35
+
36
+ // src/catch-exception.ts
37
+ function catchException(handler) {
38
+ return async function catchException2(ctx, next) {
39
+ try {
40
+ await next();
41
+ } catch (err) {
42
+ await handler(err);
43
+ }
44
+ };
45
+ }
46
+ // Annotate the CommonJS export names for ESM import in node:
47
+ 0 && (module.exports = {
48
+ catchException,
49
+ throwException
50
+ });
51
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/throw-exception.ts","../src/catch-exception.ts"],"sourcesContent":["export * from './throw-exception.js'\nexport * from './catch-exception.js'\n","import { KeqContext, KeqMiddleware } from 'keq'\nimport { Promisable } from 'type-fest'\n\n\nexport type Check = (ctx: KeqContext) => Promisable<void>\n\nexport function throwException(check: Check): KeqMiddleware {\n return async function throwException(ctx, next) {\n await next()\n\n await check(ctx)\n }\n}\n","import { KeqMiddleware } from 'keq'\nimport { Promisable } from 'type-fest'\n\n\nexport function catchException(handler: (e: unknown) => Promisable<void>): KeqMiddleware {\n return async function catchException(ctx, next) {\n try {\n await next()\n } catch (err) {\n await handler(err)\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMO,SAAS,eAAe,OAA6B;AAC1D,SAAO,eAAeA,gBAAe,KAAK,MAAM;AAC9C,UAAM,KAAK;AAEX,UAAM,MAAM,GAAG;AAAA,EACjB;AACF;;;ACRO,SAAS,eAAe,SAA0D;AACvF,SAAO,eAAeC,gBAAe,KAAK,MAAM;AAC9C,QAAI;AACF,YAAM,KAAK;AAAA,IACb,SAAS,KAAK;AACZ,YAAM,QAAQ,GAAG;AAAA,IACnB;AAAA,EACF;AACF;","names":["throwException","catchException"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,23 @@
1
+ // src/throw-exception.ts
2
+ function throwException(check) {
3
+ return async function throwException2(ctx, next) {
4
+ await next();
5
+ await check(ctx);
6
+ };
7
+ }
8
+
9
+ // src/catch-exception.ts
10
+ function catchException(handler) {
11
+ return async function catchException2(ctx, next) {
12
+ try {
13
+ await next();
14
+ } catch (err) {
15
+ await handler(err);
16
+ }
17
+ };
18
+ }
19
+ export {
20
+ catchException,
21
+ throwException
22
+ };
23
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/throw-exception.ts","../src/catch-exception.ts"],"sourcesContent":["import { KeqContext, KeqMiddleware } from 'keq'\nimport { Promisable } from 'type-fest'\n\n\nexport type Check = (ctx: KeqContext) => Promisable<void>\n\nexport function throwException(check: Check): KeqMiddleware {\n return async function throwException(ctx, next) {\n await next()\n\n await check(ctx)\n }\n}\n","import { KeqMiddleware } from 'keq'\nimport { Promisable } from 'type-fest'\n\n\nexport function catchException(handler: (e: unknown) => Promisable<void>): KeqMiddleware {\n return async function catchException(ctx, next) {\n try {\n await next()\n } catch (err) {\n await handler(err)\n }\n }\n}\n"],"mappings":";AAMO,SAAS,eAAe,OAA6B;AAC1D,SAAO,eAAeA,gBAAe,KAAK,MAAM;AAC9C,UAAM,KAAK;AAEX,UAAM,MAAM,GAAG;AAAA,EACjB;AACF;;;ACRO,SAAS,eAAe,SAA0D;AACvF,SAAO,eAAeC,gBAAe,KAAK,MAAM;AAC9C,QAAI;AACF,YAAM,KAAK;AAAA,IACb,SAAS,KAAK;AACZ,YAAM,QAAQ,GAAG;AAAA,IACnB;AAAA,EACF;AACF;","names":["throwException","catchException"]}
@@ -0,0 +1,5 @@
1
+ import { KeqContext, KeqMiddleware } from 'keq';
2
+ import { Promisable } from 'type-fest';
3
+ export type Check = (ctx: KeqContext) => Promisable<void>;
4
+ export declare function throwException(check: Check): KeqMiddleware;
5
+ //# sourceMappingURL=throw-exception.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"throw-exception.d.ts","sourceRoot":"","sources":["../src/throw-exception.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,KAAK,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAGtC,MAAM,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,UAAU,KAAK,UAAU,CAAC,IAAI,CAAC,CAAA;AAEzD,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,aAAa,CAM1D"}
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@keq-request/exception",
3
+ "version": "5.0.0-alpha.10",
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.10"
37
+ },
38
+ "peerDependencies": {
39
+ "keq": "^5.0.0-alpha.10"
40
+ },
41
+ "scripts": {
42
+ "build": "tsup",
43
+ "dev": "tsup --watch",
44
+ "test": "jest",
45
+ "test:update": "jest -u"
46
+ }
47
+ }