@onion-interceptor/pipes
Advanced tools
Comparing version 0.0.3-beta to 0.0.5-beta
import { operate as r } from "onion-interceptor"; | ||
const w = (a) => r(async (c, t) => { | ||
const w = (a) => r(async (o, t) => { | ||
try { | ||
await t(); | ||
} catch (c) { | ||
throw c; | ||
} finally { | ||
a(); | ||
} | ||
}), h = (a) => r(async (c, t) => { | ||
}), h = (a) => r(async (o, t) => { | ||
try { | ||
await t(); | ||
} catch (o) { | ||
throw a(o); | ||
} catch (c) { | ||
throw a(c); | ||
} | ||
}), i = (a) => r(async (c, t) => { | ||
await new Promise((o) => setTimeout(o, a)), await t(); | ||
}), e = function(a, c, t) { | ||
return r(async (o, s) => { | ||
}), e = (a) => r(async (o, t) => { | ||
await new Promise((c) => setTimeout(c, a)), await t(); | ||
}), i = function(a, o, t) { | ||
return r(async (c, s) => { | ||
try { | ||
await s(), a(o); | ||
await s(), a(c); | ||
} catch (n) { | ||
throw (c == null ? void 0 : c(n)) ?? n; | ||
throw (o == null ? void 0 : o(n)) ?? n; | ||
} finally { | ||
@@ -29,5 +31,5 @@ t == null || t(); | ||
h as catchError, | ||
i as delay, | ||
e as delay, | ||
w as finalize, | ||
e as tap | ||
i as tap | ||
}; |
{ | ||
"name": "@onion-interceptor/pipes", | ||
"version": "0.0.3-beta", | ||
"version": "0.0.5-beta", | ||
"type": "module", | ||
@@ -33,5 +33,8 @@ "description": "onion-interceptor pipes", | ||
"peerDependencies": { | ||
"onion-interceptor": "latest" | ||
"onion-interceptor": "0.0.5-beta" | ||
}, | ||
"devDependencies": { | ||
"onion-interceptor": "workspace:*" | ||
}, | ||
"license": "ISC" | ||
} |
@@ -29,15 +29,17 @@ # @onion-interceptor/pipes | ||
> 捕获错误 | ||
```typescript | ||
import { catchError } from '@onion-interceptor/pipes' | ||
import type { Next, Context } from 'onion-interceptor' | ||
import { catchError } from "@onion-interceptor/pipes"; | ||
import type { Next, Context } from "onion-interceptor"; | ||
export async function errorInterceptor(ctx: Context, next: Next) { | ||
console.log('errorInterceptor start', ctx) | ||
console.log("errorInterceptor start", ctx); | ||
await next( | ||
catchError((err) => { | ||
console.log(error) | ||
return Promise.reject(error) | ||
console.log(error); | ||
return Promise.reject(error); | ||
}) | ||
) | ||
console.log('errorInterceptor end', ctx) | ||
); | ||
console.log("errorInterceptor end", ctx); | ||
} | ||
@@ -48,2 +50,4 @@ ``` | ||
> finalize 是一个操作管道,用于在请求或响应完成时执行一些操作(不管成功或失败)。 | ||
```typescript | ||
@@ -61,17 +65,19 @@ import { finalize } from '@onion-interceptor/pipes' | ||
> tap 是一个操作管道,可接受三个回调函数,后两个选填 分别为 成功后的回调,错误回调,无论成功还是失败都会执行的回调。 | ||
```typescript | ||
import { tap } from '@onion-interceptor/pipes' | ||
import { tap } from "@onion-interceptor/pipes"; | ||
export async function errorInterceptor(ctx: Context, next: Next) { | ||
console.log('errorInterceptor start', ctx) | ||
console.log("errorInterceptor start", ctx); | ||
await next( | ||
tap( | ||
(_ctx) => console.log('find error in res', _ctx.res), | ||
(_ctx) => console.log("find error in res", _ctx.res), | ||
(error) => { | ||
console.log(error) | ||
return Promise.reject(error) | ||
console.log(error); | ||
return Promise.reject(error); | ||
}, | ||
() => console.log('errorInterceptor end', ctx) | ||
() => console.log("errorInterceptor end", ctx) | ||
) | ||
) | ||
); | ||
} | ||
@@ -82,2 +88,4 @@ ``` | ||
> 延迟拦截器 | ||
```typescript | ||
@@ -100,2 +108,2 @@ import type { Next, Context } from 'onion-interceptor' | ||
本项目使用 MIT 许可证。 | ||
本项目使用 MIT 许可证。 |
4671
47
105
1