npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@soapi/middlewares

v2.0.9

Published

前端sdk中间件

Downloads

198

Readme

@soapi/middlewares

@soapi/sdk常用中间件。

Install

npm install @soapi/middlewares

or use yarn

yarn add @soapi/middlewares

Usage

compose(middlewares)

参数是一个middleware数组。将多个middleware组合成一个新的middleware。

checkSchema([errorHandler])

校验接口参数和返回值是否符合接口平台定义的规范。 errorHandler是一个可选参数,处理校验错误。如果不穿此参数,错误会被抛出。

setEnv()

设置环境变量,影响最终请求的url地址。

setHeader(key, value)

设置请求的Header。

catchError(errorHandler)

捕获错误并对错误进行处理。catchError只会处理后面中间件抛出的错误,app.usekoa的洋葱模型一致。

app.use(catchError(error => {
    console.log('what the fuck!')

    /**
     * 这里如果不抛出错误
     * sdk会认为您已经将错误正确的处理,并将继续执行
     * 这将导致sdk的api被调用时候,向外抛出的错误被中间件拦截并处理
     * 调用的地方将无法得知错误的发生,并按照正常调用处理
     */
    throw error
  }))

sdk会认为您已经将错误正确的处理,并将继续执行 这将导致sdk的api被调用时候,向外抛出的错误被中间件拦截并处理 调用的地方将无法得知错误的发生,并按照正常调用处理

Q&A

错误上报

import { sendError } from 'sheinq'
import { catchError } from '@soapi/middlewares'

const reportErrorMiddleware = catchError(error => {
  sendError(error)
  throw error
})

app
  .use(reportErrorMiddleware)
  // checkSchema写在后面,report
  .use(checkSchema())