MCPcopy
hub / github.com/HisMax/RedInk / getApiErrorPayload

Function getApiErrorPayload

frontend/src/api/client.ts:6–35  ·  view source on GitHub ↗
(error: unknown, fallback: string)

Source from the content-addressed store, hash-verified

4export const API_BASE_URL = '/api'
5
6export function getApiErrorPayload(error: unknown, fallback: string): {
7 error: AppError | string
8 error_message: string
9} {
10 if (axios.isAxiosError(error)) {
11 if (error.code === 'ECONNABORTED') {
12 return {
13 error: '请求超时,请检查网络连接',
14 error_message: '请求超时,请检查网络连接'
15 }
16 }
17 if (!error.response) {
18 return {
19 error: '网络连接失败,请检查网络设置',
20 error_message: '网络连接失败,请检查网络设置'
21 }
22 }
23 const data = error.response.data || {}
24 const message = data.error_message || fallback
25 return {
26 error: data.error || message,
27 error_message: message
28 }
29 }
30
31 return {
32 error: fallback,
33 error_message: fallback
34 }
35}
36
37export async function readErrorResponse(response: Response, fallback: string) {
38 try {

Callers 7

createHistoryFunction · 0.90
getHistoryListFunction · 0.90
getHistoryFunction · 0.90
updateHistoryFunction · 0.90
deleteHistoryFunction · 0.90
searchHistoryFunction · 0.90
getHistoryStatsFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected