signoz/frontend/src/utils/errorUtils.ts
SagarRajput-7 0f5825a2b3
chore: product link and retires retry condition (#9018)
* feat: product link and retires retry condition

* feat: retry logic for 4xx and 5xx

* chore: tooltip editorial changes (#9019)

* chore: tooltip editorial changes

* feat: fixed lint error and styling

---------

Co-authored-by: SagarRajput-7 <sagar@signoz.io>

* feat: added test cases

* feat: fixed lint error

* feat: added product link in single select for dyn variables

---------

Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
2025-09-07 13:36:12 +05:30

29 lines
1.1 KiB
TypeScript

/**
* Extracts HTTP status code from various error types
* @param error - The error object (could be APIError, AxiosError, or other error types)
* @returns HTTP status code if available, undefined otherwise
*/
export const getHttpStatusCode = (error: any): number | undefined => {
if (!error) return undefined;
// Try to get status code from APIError instance (transformed by ErrorResponseHandlerV2)
if (typeof error.getHttpStatusCode === 'function') {
return error.getHttpStatusCode();
}
// Fallback for AxiosError or other error types
return error?.response?.status || error?.status;
};
/**
* Determines if an error is retryable based on HTTP status code
* @param error - The error object
* @returns true if error is retryable (5xx server errors), false for 4xx client errors
*/
export const isRetryableError = (error: any): boolean => {
const statusCode = getHttpStatusCode(error);
// 4xx errors are client errors (not retryable), 5xx errors are server errors (retryable)
// If no status code is available, default to retryable
return !statusCode || statusCode >= 500;
};