import { AxiosError } from 'axios'; import { AUTH_RESPONSES } from '../constants/authResponses'; import HTTP_STATUS_CODE from '../constants/httpStatusCode'; export class AuthError extends Error { status: number; error_detail: AUTH_RESPONSES; body: Record; constructor({ response: error }: AxiosError) { const error_data = (error?.data as Record) || {}; const message = error_data.description || 'internal server error'; super(`AuthError: ${message}`); this.name = 'AuthError'; this.body = error_data; this.message = message; this.status = error?.status || HTTP_STATUS_CODE.INTERNAL_SERVER_ERROR; this.error_detail = error_data.error_detail || AUTH_RESPONSES.INTERNAL_SERVER_ERROR; } } export default AuthError;