xdoer / PreQuest

A Modular And Pluggable Solution For HTTP Request.
https://pre-quest.vercel.app
MIT License
88 stars 14 forks source link

Module '"@prequest/lock"' has no exported member 'createLockWrapper'. #28

Closed kevin0713 closed 3 years ago

kevin0713 commented 3 years ago

1624355402846

Module '"@prequest/lock"' has no exported member 'createLockWrapper'.

文档是否没有及时更新

xdoer commented 3 years ago

不好意思,忘记更新文档了。现在改为了默认导出

kevin0713 commented 3 years ago

@xdoer 非常感谢,及时更新文档。

kevin0713 commented 3 years ago

我正在使用Taro开发小程序 respones= await request('xxx') 如何在try catch 里捕获到业务errorcode,我在拦截器里使用Promise.reject(data) 并没有起作用。

import { PreQuest, create } from '@prequest/miniprogram' import { InterceptorMiddleware } from '@prequest/interceptor' import Taro from '@tarojs/taro'

const interceptor = new InterceptorMiddleware() const prequest:any = create(Taro.request, opt)

interceptor.response.use(async(response:any)=>{

  const data=response.data

  switch (data.errorcode){
      case 0:
        return data
      default:

       return  Promise.reject(data)
  }

}, error => {

console.log('parse response fail', error)

} )

export default prequest

xdoer commented 3 years ago

拦截器里抛异常不要使用Promise.reject,直接throw data 就可以.

kevin0713 commented 3 years ago

不好意思,可能我没有把问题描述清楚。

import { prequest } from './prequest'

async function getData() { try {

const res = await prequest('/api', opt)

} catch (e) {

// 我如何捕捉到拦截器中返回的 errorcode !==0 的业务data? console.log(e) } }

xdoer commented 3 years ago

@kevin0713 在拦截器的 error 回调函数里,再把错误抛出去即可。

xdoer commented 3 years ago

待会儿我补个 demo

kevin0713 commented 3 years ago

@xdoer Many thanks.:smile:

xdoer commented 3 years ago

@kevin0713 issuses 先关闭了,有问题再提一个 issuses 或者加QQ群: 168837667 聊一下