feat: enhance strategy deletion process with user feedback and validation checks

This commit is contained in:
Dean
2026-03-27 13:51:32 +08:00
committed by shinchan-zhai
parent b331733e23
commit 6cb6c31b34
6 changed files with 121 additions and 40 deletions

View File

@@ -19,20 +19,20 @@ export const dataApi = {
return result.data!
},
async getAccount(traderId?: string): Promise<AccountInfo> {
async getAccount(traderId?: string, silent?: boolean): Promise<AccountInfo> {
const url = traderId
? `${API_BASE}/account?trader_id=${traderId}`
: `${API_BASE}/account`
const result = await httpClient.get<AccountInfo>(url)
const result = await httpClient.request<AccountInfo>(url, { silent })
if (!result.success) throw new Error('Failed to fetch account info')
return result.data!
},
async getPositions(traderId?: string): Promise<Position[]> {
async getPositions(traderId?: string, silent?: boolean): Promise<Position[]> {
const url = traderId
? `${API_BASE}/positions?trader_id=${traderId}`
: `${API_BASE}/positions`
const result = await httpClient.get<Position[]>(url)
const result = await httpClient.request<Position[]>(url, { silent })
if (!result.success) throw new Error('Failed to fetch positions')
return result.data!
},
@@ -48,7 +48,8 @@ export const dataApi = {
async getLatestDecisions(
traderId?: string,
limit: number = 5
limit: number = 5,
silent?: boolean
): Promise<DecisionRecord[]> {
const params = new URLSearchParams()
if (traderId) {
@@ -56,8 +57,9 @@ export const dataApi = {
}
params.append('limit', limit.toString())
const result = await httpClient.get<DecisionRecord[]>(
`${API_BASE}/decisions/latest?${params}`
const result = await httpClient.request<DecisionRecord[]>(
`${API_BASE}/decisions/latest?${params}`,
{ silent }
)
if (!result.success) throw new Error('Failed to fetch latest decisions')
return result.data!

View File

@@ -85,11 +85,16 @@ export class HttpClient {
* Only business errors are returned to caller
*/
private async handleError(error: AxiosError): Promise<any> {
const isSilent = (error.config as any)?.silentError === true
// Network error (no response from server)
if (!error.response) {
toast.error('Network error - Please check your connection', {
description: 'Unable to reach the server',
})
if (!isSilent) {
toast.error('Network error - Please check your connection', {
id: 'network-error',
description: 'Unable to reach the server',
})
}
throw new Error('Network error')
}
@@ -132,25 +137,34 @@ export class HttpClient {
// Handle 403 Forbidden - system error
if (status === 403) {
toast.error('Permission Denied', {
description: 'You do not have permission to access this resource',
})
if (!isSilent) {
toast.error('Permission Denied', {
id: 'permission-denied',
description: 'You do not have permission to access this resource',
})
}
throw new Error('Permission denied')
}
// Handle 404 Not Found - system error
if (status === 404) {
toast.error('API Not Found', {
description: 'The requested endpoint does not exist (404)',
})
if (!isSilent) {
toast.error('API Not Found', {
id: `404-${(error.config as any)?.url || 'unknown'}`,
description: 'The requested endpoint does not exist (404)',
})
}
throw new Error('API not found')
}
// Handle 500+ Server Error - system error
if (status >= 500) {
toast.error('Server Error', {
description: 'Please try again later or contact support',
})
if (!isSilent) {
toast.error('Server Error', {
id: 'server-error',
description: 'Please try again later or contact support',
})
}
throw new Error('Server error')
}
@@ -171,6 +185,7 @@ export class HttpClient {
data?: any
params?: any
headers?: Record<string, string>
silent?: boolean
} = {}
): Promise<ApiResponse<T>> {
try {
@@ -180,6 +195,7 @@ export class HttpClient {
data: options.data,
params: options.params,
headers: options.headers,
...(options.silent && { silentError: true }),
})
// Success