mirror of
https://github.com/SigNoz/signoz.git
synced 2025-12-21 01:16:57 +00:00
* chore: eslint is updated * chore: some eslint fixes are made * chore: some more eslint fix are updated * chore: some eslint fix is made * chore: styled components type is added * chore: some more eslint fix are made * chore: some more eslint fix are updated * chore: some more eslint fix are updated * fix: eslint fixes Co-authored-by: Pranshu Chittora <pranshu@signoz.io>
59 lines
1.2 KiB
TypeScript
59 lines
1.2 KiB
TypeScript
import { AxiosError } from 'axios';
|
|
import { ErrorResponse } from 'types/api';
|
|
import { ErrorStatusCode } from 'types/common';
|
|
|
|
export function ErrorResponseHandler(error: AxiosError): ErrorResponse {
|
|
const { response, request } = error;
|
|
if (response) {
|
|
// client received an error response (5xx, 4xx)
|
|
// making the error status code as standard Error Status Code
|
|
const statusCode = response.status as ErrorStatusCode;
|
|
|
|
if (statusCode >= 400 && statusCode < 500) {
|
|
const { data } = response;
|
|
|
|
if (statusCode === 404) {
|
|
return {
|
|
statusCode,
|
|
payload: null,
|
|
error: 'Not Found',
|
|
message: null,
|
|
};
|
|
}
|
|
|
|
return {
|
|
statusCode,
|
|
payload: null,
|
|
error: data.error,
|
|
message: null,
|
|
};
|
|
}
|
|
|
|
return {
|
|
statusCode,
|
|
payload: null,
|
|
error: 'Something went wrong',
|
|
message: null,
|
|
};
|
|
}
|
|
if (request) {
|
|
// client never received a response, or request never left
|
|
console.error('client never received a response, or request never left');
|
|
|
|
return {
|
|
statusCode: 500,
|
|
payload: null,
|
|
error: 'Something went wrong',
|
|
message: null,
|
|
};
|
|
}
|
|
// anything else
|
|
console.error('any');
|
|
return {
|
|
statusCode: 500,
|
|
payload: null,
|
|
error: String(error),
|
|
message: null,
|
|
};
|
|
}
|