Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: addResponseInterceptor拦截器抛出error类型错误 #4667

Closed
5 tasks done
swamp-y opened this issue Oct 17, 2024 · 3 comments · Fixed by #4679
Closed
5 tasks done

Bug: addResponseInterceptor拦截器抛出error类型错误 #4667

swamp-y opened this issue Oct 17, 2024 · 3 comments · Fixed by #4679

Comments

@swamp-y
Copy link

swamp-y commented Oct 17, 2024

Version

Vben Admin V5

Describe the bug?

image
image

addResponseInterceptor 拦截器应通过Promise返回 response对象,否则后面的token过期处理authenticateResponseInterceptor函数,以及通用错误处理errorMessageResponseInterceptor中,回调参数error,将会得到string类型错误信息 =》 Error ${status}: ${msg},无法解构code,message进行自定义判断

Reproduction

https://github.com/vbenjs/vue-vben-admin

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (16) x64 AMD Ryzen 7 5700X3D 8-Core Processor
    Memory: 18.40 GB / 31.92 GB
  Binaries:
    Node: 20.15.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.7.0 - C:\Program Files\nodejs\npm.CMD
    pnpm: 9.12.1 - C:\Program Files\nodejs\pnpm.CMD
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.22621.3527

Relevant log output

No response

Validations

@anncwb
Copy link
Collaborator

anncwb commented Oct 17, 2024

你可以直接throw 一个对象,而不是error,具体看你业务需求

swamp-y added a commit to swamp-y/vue-vben-admin that referenced this issue Oct 17, 2024
swamp-y added a commit to swamp-y/vue-vben-admin that referenced this issue Oct 17, 2024
@anncwb
Copy link
Collaborator

anncwb commented Oct 17, 2024

正常逻辑你接口报错应该不会走 fulfilled 才对,应该会走默认的 rejected,所以你需要看看你的业务逻辑。目前示例代码是接口报错是不会进入 fulfilled逻辑,所以能直接拿到error对象。你的 PR 应该也是。你看看提供你的具体场景,后面我在详细看看吧。

@swamp-y
Copy link
Author

swamp-y commented Oct 17, 2024

  1. status === 200 但是 code ===500这种,会命中fulfilled ,业务大多数是如此结构,但是直接throw new Error(),后面errorMessageResponseInterceptor处理函数中,error对象也只能拿到string,无法解构里面的code和messge进行自定义处理
  2. status === 200 && code === 401,这种情况,也会导致token过期处理函数无法解构code而命中不了过期处理逻辑
  3. 刚从v2换到v5,这块就感觉不一样了 ^_^

@github-actions github-actions bot locked and limited conversation to collaborators Nov 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants