mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-06 12:30:59 +08:00
fix: improve trader error feedback, stale balance cleanup, and claw402 warnings (#1452)
* fix: improve trader error handling and balance validation * fix: localize structured trader failure reasons --------- Co-authored-by: apple <apple@MacbookPro-zbh.local>
This commit is contained in:
@@ -19,6 +19,28 @@ export interface ApiResponse<T = any> {
|
||||
success: boolean
|
||||
data?: T
|
||||
message?: string
|
||||
errorKey?: string
|
||||
errorParams?: Record<string, string>
|
||||
statusCode?: number
|
||||
}
|
||||
|
||||
export class ApiError extends Error {
|
||||
errorKey?: string
|
||||
errorParams?: Record<string, string>
|
||||
statusCode?: number
|
||||
|
||||
constructor(
|
||||
message: string,
|
||||
errorKey?: string,
|
||||
errorParams?: Record<string, string>,
|
||||
statusCode?: number
|
||||
) {
|
||||
super(message)
|
||||
this.name = 'ApiError'
|
||||
this.errorKey = errorKey
|
||||
this.errorParams = errorParams
|
||||
this.statusCode = statusCode
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,6 +108,13 @@ export class HttpClient {
|
||||
*/
|
||||
private async handleError(error: AxiosError): Promise<any> {
|
||||
const isSilent = (error.config as any)?.silentError === true
|
||||
const errorData = error.response?.data as {
|
||||
error?: string
|
||||
message?: string
|
||||
error_key?: string
|
||||
error_params?: Record<string, string>
|
||||
} | undefined
|
||||
const serverMessage = errorData?.error || errorData?.message
|
||||
|
||||
// Network error (no response from server)
|
||||
if (!error.response) {
|
||||
@@ -98,10 +127,7 @@ export class HttpClient {
|
||||
throw new Error('Network error')
|
||||
}
|
||||
|
||||
const { status } = error.response as AxiosResponse<{
|
||||
error?: string
|
||||
message?: string
|
||||
}>
|
||||
const status = error.response?.status ?? 0
|
||||
|
||||
// Handle 401 Unauthorized
|
||||
if (status === 401) {
|
||||
@@ -159,6 +185,9 @@ export class HttpClient {
|
||||
|
||||
// Handle 500+ Server Error - system error
|
||||
if (status >= 500) {
|
||||
if (serverMessage) {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
if (!isSilent) {
|
||||
toast.error('Server Error', {
|
||||
id: 'server-error',
|
||||
@@ -212,6 +241,9 @@ export class HttpClient {
|
||||
return {
|
||||
success: false,
|
||||
message: errorData?.error || errorData?.message || 'Operation failed',
|
||||
errorKey: errorData?.error_key,
|
||||
errorParams: errorData?.error_params,
|
||||
statusCode: error.response.status,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user