mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-20 23:22:05 +08:00
feat(api): add formatAxiosError utility for handling axios errors
This commit is contained in:
parent
a65b30f3a1
commit
42fa2d94be
@ -1,4 +1,5 @@
|
|||||||
import { AgentServerError } from '@renderer/types'
|
import { AgentServerError } from '@renderer/types'
|
||||||
|
import { AxiosError } from 'axios'
|
||||||
import { t } from 'i18next'
|
import { t } from 'i18next'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -75,3 +76,13 @@ export function splitApiKeyString(keyStr: string): string[] {
|
|||||||
|
|
||||||
export const formatAgentServerError = (error: AgentServerError) =>
|
export const formatAgentServerError = (error: AgentServerError) =>
|
||||||
`${t('common.error')}: ${error.code} ${error.message}`
|
`${t('common.error')}: ${error.code} ${error.message}`
|
||||||
|
|
||||||
|
export const formatAxiosError = (error: AxiosError) => {
|
||||||
|
if (!error.response) {
|
||||||
|
return `${t('common.error')}: ${t('error.no_response')}`
|
||||||
|
}
|
||||||
|
|
||||||
|
const { status, statusText } = error.response
|
||||||
|
|
||||||
|
return `${t('common.error')}: ${status} ${statusText}`
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user