fix(api): 将错误提示从toast改为抛出异常
修改错误处理逻辑,将静默模式下的toast提示改为直接抛出异常,以便调用方能够捕获并处理错误
Showing
1 changed file
with
7 additions
and
6 deletions
| 1 | /* | 1 | /* |
| 2 | * @Date: 2022-05-18 22:56:08 | 2 | * @Date: 2022-05-18 22:56:08 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-09-16 21:56:59 | 4 | + * @LastEditTime: 2025-09-19 13:12:14 |
| 5 | * @FilePath: /lls_program/src/api/fn.js | 5 | * @FilePath: /lls_program/src/api/fn.js |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | */ | 7 | */ |
| ... | @@ -28,11 +28,12 @@ export const fn = (api, options = {}) => { | ... | @@ -28,11 +28,12 @@ export const fn = (api, options = {}) => { |
| 28 | console.warn(res); | 28 | console.warn(res); |
| 29 | // 只有在非静默模式下才显示错误提示 | 29 | // 只有在非静默模式下才显示错误提示 |
| 30 | if (!silent) { | 30 | if (!silent) { |
| 31 | - Taro.showToast({ | 31 | + // Taro.showToast({ |
| 32 | - title: res?.data?.msg || '请求失败', | 32 | + // title: res?.data?.msg || '请求失败', |
| 33 | - icon: 'none', | 33 | + // icon: 'none', |
| 34 | - duration: 2000 | 34 | + // duration: 2000 |
| 35 | - }); | 35 | + // }); |
| 36 | + throw new Error(res?.data?.msg || '请求失败'); | ||
| 36 | } | 37 | } |
| 37 | return false; | 38 | return false; |
| 38 | } | 39 | } | ... | ... |
-
Please register or login to post a comment