1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-02 20:35:25 +02:00

chore(deps): upgrade axios [EE-6488] (#10885)

Co-authored-by: Matt Hook <hookenz@gmail.com>
This commit is contained in:
Chaim Lev-Ari 2024-01-02 13:26:54 +07:00 committed by GitHub
parent 4c226d7a17
commit a1519ba737
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 116 additions and 57 deletions

View file

@ -29,7 +29,7 @@ async function getSubscriptions(environmentId: EnvironmentId) {
return data.value;
} catch (e) {
throw parseAxiosError(
e as Error,
e,
'Unable to retrieve subscriptions',
azureErrorParser
);

View file

@ -1,9 +1,22 @@
import { AxiosError } from 'axios';
export function azureErrorParser(axiosError: AxiosError) {
if (!axiosError.response) {
const error = new Error('Failed azure request');
return {
error,
details: axiosError.message,
};
}
const responseData = axiosError.response.data;
const message =
(axiosError.response?.data?.error?.message as string) ||
'Failed azure request';
responseData &&
typeof responseData === 'object' &&
'error' in responseData &&
typeof responseData.error === 'string'
? responseData.error
: `Failed azure request: ${axiosError.response?.statusText}`;
return {
error: new Error(message),

View file

@ -1,5 +1,5 @@
import { useMutation, useQueryClient } from 'react-query';
import { AxiosRequestHeaders } from 'axios';
import { RawAxiosRequestHeaders } from 'axios';
import axios, { parseAxiosError } from '@/portainer/services/axios';
import {
@ -282,7 +282,7 @@ async function createContainer(
{ nodeName }: { nodeName?: string } = {}
) {
try {
const headers: AxiosRequestHeaders = {};
const headers: RawAxiosRequestHeaders = {};
if (nodeName) {
headers['X-PortainerAgent-Target'] = nodeName;

View file

@ -1,4 +1,4 @@
import { AxiosRequestHeaders } from 'axios';
import { RawAxiosRequestHeaders } from 'axios';
import { EnvironmentId } from '@/react/portainer/environments/types';
import PortainerError from '@/portainer/error';
@ -12,7 +12,7 @@ export async function startContainer(
id: ContainerId,
{ nodeName }: { nodeName?: string } = {}
) {
const headers: AxiosRequestHeaders = {};
const headers: RawAxiosRequestHeaders = {};
if (nodeName) {
headers['X-PortainerAgent-Target'] = nodeName;
@ -34,7 +34,7 @@ export async function stopContainer(
id: ContainerId,
{ nodeName }: { nodeName?: string } = {}
) {
const headers: AxiosRequestHeaders = {};
const headers: RawAxiosRequestHeaders = {};
if (nodeName) {
headers['X-PortainerAgent-Target'] = nodeName;
@ -49,7 +49,7 @@ export async function recreateContainer(
pullImage: boolean,
{ nodeName }: { nodeName?: string } = {}
) {
const headers: AxiosRequestHeaders = {};
const headers: RawAxiosRequestHeaders = {};
if (nodeName) {
headers['X-PortainerAgent-Target'] = nodeName;
@ -69,7 +69,7 @@ export async function restartContainer(
id: ContainerId,
{ nodeName }: { nodeName?: string } = {}
) {
const headers: AxiosRequestHeaders = {};
const headers: RawAxiosRequestHeaders = {};
if (nodeName) {
headers['X-PortainerAgent-Target'] = nodeName;
@ -87,7 +87,7 @@ export async function killContainer(
id: ContainerId,
{ nodeName }: { nodeName?: string } = {}
) {
const headers: AxiosRequestHeaders = {};
const headers: RawAxiosRequestHeaders = {};
if (nodeName) {
headers['X-PortainerAgent-Target'] = nodeName;
@ -101,7 +101,7 @@ export async function pauseContainer(
id: ContainerId,
{ nodeName }: { nodeName?: string } = {}
) {
const headers: AxiosRequestHeaders = {};
const headers: RawAxiosRequestHeaders = {};
if (nodeName) {
headers['X-PortainerAgent-Target'] = nodeName;
@ -115,7 +115,7 @@ export async function resumeContainer(
id: ContainerId,
{ nodeName }: { nodeName?: string } = {}
) {
const headers: AxiosRequestHeaders = {};
const headers: RawAxiosRequestHeaders = {};
if (nodeName) {
headers['X-PortainerAgent-Target'] = nodeName;
@ -134,7 +134,7 @@ export async function renameContainer(
name: string,
{ nodeName }: { nodeName?: string } = {}
) {
const headers: AxiosRequestHeaders = {};
const headers: RawAxiosRequestHeaders = {};
if (nodeName) {
headers['X-PortainerAgent-Target'] = nodeName;
@ -156,7 +156,7 @@ export async function removeContainer(
}: { removeVolumes?: boolean; nodeName?: string } = {}
) {
try {
const headers: AxiosRequestHeaders = {};
const headers: RawAxiosRequestHeaders = {};
if (nodeName) {
headers['X-PortainerAgent-Target'] = nodeName;

View file

@ -1,5 +1,5 @@
import { Resources, RestartPolicy } from 'docker-types/generated/1.41';
import { AxiosRequestHeaders } from 'axios';
import { RawAxiosRequestHeaders } from 'axios';
import axios, { parseAxiosError } from '@/portainer/services/axios';
import { EnvironmentId } from '@/react/portainer/environments/types';
@ -22,7 +22,7 @@ export async function updateContainer(
config: UpdateConfig,
{ nodeName }: { nodeName?: string } = {}
) {
const headers: AxiosRequestHeaders = {};
const headers: RawAxiosRequestHeaders = {};
if (nodeName) {
headers['X-PortainerAgent-Target'] = nodeName;

View file

@ -1,4 +1,4 @@
import { AxiosRequestHeaders } from 'axios';
import { RawAxiosRequestHeaders } from 'axios';
import axios, { parseAxiosError } from '@/portainer/services/axios';
import { EnvironmentId } from '@/react/portainer/environments/types';
@ -31,7 +31,7 @@ export async function pullImage({
const imageURI = buildImageFullURI(image, registry);
const headers: AxiosRequestHeaders = {
const headers: RawAxiosRequestHeaders = {
'X-Registry-Auth': authenticationDetails,
};

View file

@ -1,5 +1,5 @@
import { EndpointSettings } from 'docker-types/generated/1.41';
import { AxiosRequestHeaders } from 'axios';
import { RawAxiosRequestHeaders } from 'axios';
import { useMutation, useQueryClient } from 'react-query';
import axios, { parseAxiosError } from '@/portainer/services/axios';
@ -56,7 +56,7 @@ export async function connectContainer({
};
}
const headers: AxiosRequestHeaders = {};
const headers: RawAxiosRequestHeaders = {};
if (nodeName) {
headers['X-PortainerAgent-Target'] = nodeName;

View file

@ -1,7 +1,10 @@
import { AxiosError } from 'axios';
import { useQuery } from 'react-query';
import axios, { parseAxiosError } from '@/portainer/services/axios';
import axios, {
isDefaultResponse,
parseAxiosError,
} from '@/portainer/services/axios';
interface Creds {
username?: string;
@ -45,8 +48,10 @@ export async function checkRepo(
);
return true;
} catch (error) {
throw parseAxiosError(error as Error, '', (axiosError: AxiosError) => {
let details = axiosError.response?.data.details;
throw parseAxiosError(error, '', (axiosError: AxiosError) => {
let details = isDefaultResponse(axiosError.response?.data)
? axiosError.response?.data.details || ''
: '';
const { creds = {} } = options;
// If no credentials were provided alter error from git to indicate repository is not found or is private

View file

@ -37,7 +37,7 @@ describe('getLicenses', () => {
const promise = getLicenses();
await promise.then(thenFn, catchFn);
expect(catchFn).toHaveBeenCalledWith(new Error(message));
expect(catchFn).toHaveBeenCalledWith(new Error(details));
expect(thenFn).not.toHaveBeenCalled();
});
});

View file

@ -1,7 +1,7 @@
import _ from 'lodash';
import { AxiosError } from 'axios';
import axios from '@/portainer/services/axios';
import axios, { parseAxiosError } from '@/portainer/services/axios';
import { License, LicenseInfo } from './types';
@ -25,8 +25,7 @@ export async function getLicenses() {
return data;
} catch (e) {
const axiosError = e as AxiosError;
throw new Error(axiosError.response?.data.message);
throw parseAxiosError(e);
}
}
@ -55,7 +54,7 @@ export async function attachLicense(licenseKeys: string[]) {
'Your session has expired, please refresh the browser and log in again.'
);
}
throw new Error(axiosError.response?.data.message);
throw parseAxiosError(e);
}
}
@ -76,8 +75,7 @@ export async function removeLicense(licenseKeys: string[]) {
getLicenseInfo();
return data;
} catch (e) {
const axiosError = e as AxiosError;
throw new Error(axiosError.response?.data.message);
throw parseAxiosError(e);
}
}
@ -105,8 +103,7 @@ export async function getLicenseInfo() {
return info;
} catch (e) {
const axiosError = e as AxiosError;
throw new Error(axiosError.response?.data.message);
throw parseAxiosError(e);
}
}