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 b9a33ce809
commit 85e1f7f963
6 changed files with 121 additions and 40 deletions

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