You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/app/react/kubernetes/axiosError.ts

30 lines
829 B

import { Status } from 'kubernetes-types/meta/v1';
import { AxiosError } from 'axios';
import {
defaultErrorParser,
parseAxiosError,
} from '@/portainer/services/axios';
export function kubernetesErrorParser(axiosError: AxiosError) {
const responseStatus = axiosError.response?.data as Status;
const { message } = responseStatus;
if (message) {
return {
error: new Error(message),
details: message,
};
}
return defaultErrorParser(axiosError);
}
/**
* Parses an Axios error response from the Kubernetes API.
* @param err The Axios error object.
* @param msg An optional error message to prepend.
* @returns An error object with an error message and details.
*/
export function parseKubernetesAxiosError(err: Error, msg = '') {
return parseAxiosError(err, msg, kubernetesErrorParser);
}