xdoer / PreQuest

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

Taro v3.2.10 请求锁报错 #29

Closed liwenjun95 closed 3 years ago

liwenjun95 commented 3 years ago

图片 图片 请求token接口获取到token,赋值给ctx.request.headers['Authorization'] 时报Unhandled promise rejection TypeError: Cannot set property 'Authorization' of undefined

xdoer commented 3 years ago

改成这样

ctx.request.headers = ctx.request.headers || {}
ctx.request.headers['Authorization'] = 'Bearer' + 'xxx'
liwenjun95 commented 3 years ago

改成这样

ctx.request.headers = ctx.request.headers || {}
ctx.request.headers['Authorization'] = 'Bearer' + 'xxx'

谢谢 大佬

改成这样

ctx.request.headers = ctx.request.headers || {}
ctx.request.headers['Authorization'] = 'Bearer' + 'xxx'

图片 图片 请求头没Authorization

xdoer commented 3 years ago

然后你看一下这里的文档:请求锁。。在一些平台上发的文档比较旧。。

我看你的截图,wrapper 函数第二个参数是不需要传的

prequest.use(async (ctx, next) => {
  if (ctx.request.skipTokenCheck) return next()

  const token = await wrapper(() => prequest('/token', { skipTokenCheck: true }).then(res => res.data))
  ctx.request.headers = ctx.request.headers || {}
  ctx.request.headers['Authorization'] = `bearer ${token}`
  await next()
})
xdoer commented 3 years ago

改成这样

ctx.request.headers = ctx.request.headers || {}
ctx.request.headers['Authorization'] = 'Bearer' + 'xxx'

谢谢 大佬

改成这样

ctx.request.headers = ctx.request.headers || {}
ctx.request.headers['Authorization'] = 'Bearer' + 'xxx'

图片 图片 请求头没Authorization

小程序里是 header, 不是 headers image

xdoer commented 3 years ago

小程序参数列表,看一下这个文档:https://pre-quest.vercel.app/#/miniprogram

liwenjun95 commented 3 years ago

然后你看一下这里的文档:请求锁。。在一些平台上发的文档比较旧。。

我看你的截图,wrapper 函数第二个参数是不需要传的

prequest.use(async (ctx, next) => {
  if (ctx.request.skipTokenCheck) return next()

  const token = await wrapper(() => prequest('/token', { skipTokenCheck: true }).then(res => res.data))
  ctx.request.headers = ctx.request.headers || {}
  ctx.request.headers['Authorization'] = `bearer ${token}`
  await next()
})

改成这样

ctx.request.headers = ctx.request.headers || {}
ctx.request.headers['Authorization'] = 'Bearer' + 'xxx'

谢谢 大佬

改成这样

ctx.request.headers = ctx.request.headers || {}
ctx.request.headers['Authorization'] = 'Bearer' + 'xxx'

图片 图片 请求头没Authorization

小程序里是 header, 不是 headers image

OK了 谢谢 大佬指导!!