* 处理网络请求错误 * @param {Error} error - 错误对象 * @param {string} context - 错误上下文
(error, context = '网络请求')
| 63 | * @param {string} context - 错误上下文 |
| 64 | */ |
| 65 | static handleNetworkError(error, context = '网络请求') { |
| 66 | let customMessage = null |
| 67 | |
| 68 | if (error?.code === 'NETWORK_ERROR') { |
| 69 | customMessage = '网络连接失败,请检查网络设置' |
| 70 | } else if (error?.status === 401) { |
| 71 | customMessage = '认证失败,请重新登录' |
| 72 | } else if (error?.status === 403) { |
| 73 | customMessage = '权限不足,无法执行此操作' |
| 74 | } else if (error?.status === 404) { |
| 75 | customMessage = '请求的资源不存在' |
| 76 | } else if (error?.status >= 500) { |
| 77 | customMessage = '服务器错误,请稍后重试' |
| 78 | } |
| 79 | |
| 80 | return this.handleError(error, context, { customMessage }) |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * 处理聊天相关错误 |
nothing calls this directly
no test coverage detected