Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@onion-interceptor/pipes
Advanced tools
@onion-interceptor/pipes
是一个操作管道工具,它允许您以一种更简洁的方式编写请求拦截器。
使用 npm 或 yarn 或 pnpm 安装 @onion-interceptor/pipes
:
npm install @onion-interceptor/pipes
或者
yarn add @onion-interceptor/pipes
或者
pnpm add @onion-interceptor/pipes
捕获错误
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);
await next(
catchError((err) => {
console.log(error);
return Promise.reject(error);
})
);
console.log("errorInterceptor end", ctx);
}
finalize 是一个操作管道,用于在请求或响应完成时执行一些操作(不管成功或失败)。
import { finalize } from '@onion-interceptor/pipes'
import type { Next, Context } from 'onion-interceptor'
export async function loadingInterceptor(ctx: Context, next: Next) {
console.log('loadingInterceptor start', ctx)
await next(finally(() => console.log('loadingInterceptor end', ctx)))
}
tap 是一个操作管道,可接受三个回调函数,后两个选填 分别为 成功后的回调,错误回调,无论成功还是失败都会执行的回调。
import { tap } from "@onion-interceptor/pipes";
export async function errorInterceptor(ctx: Context, next: Next) {
console.log("errorInterceptor start", ctx);
await next(
tap(
(_ctx) => console.log("find error in res", _ctx.res),
(error) => {
console.log(error);
return Promise.reject(error);
},
() => console.log("errorInterceptor end", ctx)
)
);
}
延迟拦截器
import type { Next, Context } from 'onion-interceptor'
import { delay,finalize } from '@onion-interceptor/pipes'
export async function loadingInterceptor(ctx: Context, next: Next) {
console.log('loadingInterceptor start', ctx)
// 延迟 1 秒才执行
await next(delay(1000),finally(() => console.log('loadingInterceptor end', ctx)))
}
如果你有任何疑问或建议,欢迎提交 issue 或 PR。
本项目使用 MIT 许可证。
FAQs
onion-interceptor pipes
The npm package @onion-interceptor/pipes receives a total of 17 weekly downloads. As such, @onion-interceptor/pipes popularity was classified as not popular.
We found that @onion-interceptor/pipes demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.