1.1 KiB
1.1 KiB
Task Detail
2025-12-18 Session 5
Execution Reason
User reported that the frontend was displaying a generic "Request failed with status code 401" error instead of the specific "用户不存在" message returned by the backend in the data.message field.
Execution Process
- Analysis: Examined
src/service/request/index.ts. The response interceptor's error handler (onRejected) was hardcoding messages for 401, 403, etc., ignoring themessagefield from the backend response body (error.response.data.message). - Fix: Updated the error handling logic to prioritize
error.response.data?.messageif it exists. If not, it falls back to the default status code descriptions. - Refinement: Ensured
Promise.rejectreturns a newErrorobject with the refined message, so calling code (try/catch) receives the correct error text.
Execution Result
- The application will now display the specific error message returned by the backend (e.g., "用户不存在") in the global message toast and in
catchblocks, improving the user experience and debugging capability.