mirror of
https://github.com/portainer/portainer.git
synced 2025-08-05 05:45:22 +02:00
fix(errors): surface react docker errors to front end [EE-7053] (#11726)
Co-authored-by: testa113 <testa113>
This commit is contained in:
parent
55667a878a
commit
6b5a402962
17 changed files with 107 additions and 142 deletions
|
@ -1,10 +1,9 @@
|
|||
import { ContainerId } from '@/react/docker/containers/types';
|
||||
import axios, {
|
||||
agentTargetHeader,
|
||||
parseAxiosError,
|
||||
} from '@/portainer/services/axios';
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
import { EnvironmentId } from '@/react/portainer/environments/types';
|
||||
|
||||
import { addNodeHeader } from '../proxy/addNodeHeader';
|
||||
|
||||
import { NetworkId, DockerNetwork } from './types';
|
||||
|
||||
type NetworkAction = 'connect' | 'disconnect' | 'create';
|
||||
|
@ -14,20 +13,15 @@ export async function getNetwork(
|
|||
networkId: NetworkId,
|
||||
{ nodeName }: { nodeName?: string } = {}
|
||||
) {
|
||||
const headers = addNodeHeader(nodeName);
|
||||
try {
|
||||
const { data: network } = await axios.get<DockerNetwork>(
|
||||
buildUrl(environmentId, networkId),
|
||||
nodeName
|
||||
? {
|
||||
headers: {
|
||||
[agentTargetHeader]: nodeName,
|
||||
},
|
||||
}
|
||||
: undefined
|
||||
{ headers }
|
||||
);
|
||||
return network;
|
||||
} catch (e) {
|
||||
throw parseAxiosError(e as Error, 'Unable to retrieve network details');
|
||||
throw parseAxiosError(e, 'Unable to retrieve network details');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,7 +33,7 @@ export async function deleteNetwork(
|
|||
await axios.delete(buildUrl(environmentId, networkId));
|
||||
return networkId;
|
||||
} catch (e) {
|
||||
throw parseAxiosError(e as Error, 'Unable to remove network');
|
||||
throw parseAxiosError(e, 'Unable to remove network');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,10 +49,7 @@ export async function disconnectContainer(
|
|||
});
|
||||
return { networkId, environmentId };
|
||||
} catch (e) {
|
||||
throw parseAxiosError(
|
||||
e as Error,
|
||||
'Unable to disconnect container from network'
|
||||
);
|
||||
throw parseAxiosError(e, 'Unable to disconnect container from network');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { EndpointSettings } from 'docker-types/generated/1.41';
|
||||
import { RawAxiosRequestHeaders } from 'axios';
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
|
||||
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
||||
|
@ -11,6 +10,7 @@ import {
|
|||
} from '@/react-tools/react-query';
|
||||
|
||||
import { queryKeys as dockerQueryKeys } from '../../queries/utils';
|
||||
import { addNodeHeader } from '../../proxy/addNodeHeader';
|
||||
|
||||
import { buildUrl } from './buildUrl';
|
||||
|
||||
|
@ -56,18 +56,15 @@ export async function connectContainer({
|
|||
};
|
||||
}
|
||||
|
||||
const headers: RawAxiosRequestHeaders = {};
|
||||
|
||||
if (nodeName) {
|
||||
headers['X-PortainerAgent-Target'] = nodeName;
|
||||
}
|
||||
const headers = addNodeHeader(nodeName);
|
||||
|
||||
try {
|
||||
await axios.post(
|
||||
buildUrl(environmentId, { id: networkId, action: 'connect' }),
|
||||
payload
|
||||
payload,
|
||||
{ headers }
|
||||
);
|
||||
} catch (err) {
|
||||
throw parseAxiosError(err as Error, 'Unable to connect container');
|
||||
throw parseAxiosError(err, 'Unable to connect container');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,6 +54,6 @@ export async function getNetworks(
|
|||
network.Attachable === true)
|
||||
);
|
||||
} catch (err) {
|
||||
throw parseAxiosError(err as Error, 'Unable to retrieve networks');
|
||||
throw parseAxiosError(err, 'Unable to retrieve networks');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue