Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

front: fix api and network errors not being caught and displayed in infra editor #10516

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { getSwitchesLayerProps, getSwitchesNameLayerProps } from 'common/Map/Lay
import { useInfraID } from 'common/osrdContext';
import { getMap } from 'reducers/map/selectors';
import { useAppDispatch } from 'store';
import { castErrorToFailure } from 'utils/error';

const SwitchEditionLayers = () => {
const dispatch = useAppDispatch();
Expand Down Expand Up @@ -79,7 +80,7 @@ const SwitchEditionLayers = () => {
setTrackStatus({
type: 'error',
trackSectionID: hoveredTrackId,
message: e instanceof Error ? e.message : undefined,
message: castErrorToFailure(e).message,
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@ export default function ActionsBar({ infra, isFocused, setIsFocused, inputValue
setIsWaiting(true);
try {
if (action === InfraLockState.LOCK) {
await lockInfra({ infraId: infra.id });
await lockInfra({ infraId: infra.id }).unwrap();
}
if (action === InfraLockState.UNLOCK) {
await unlockInfra({ infraId: infra.id });
await unlockInfra({ infraId: infra.id }).unwrap();
}
} catch (e) {
if (e instanceof Error) {
dispatch(setFailure(castErrorToFailure(e)));
}
dispatch(setFailure(castErrorToFailure(e)));
} finally {
setIsWaiting(false);
}
Expand All @@ -53,17 +51,10 @@ export default function ActionsBar({ infra, isFocused, setIsFocused, inputValue
if (!isWaiting) {
setIsWaiting(true);
try {
const railjson = await getRailjson({ infraId: infra.id });
fileDownload(JSON.stringify(railjson.data), `${infra.name}.id${infra.id}.railjson.json`);
const railjson = await getRailjson({ infraId: infra.id }).unwrap();
fileDownload(JSON.stringify(railjson), `${infra.name}.id${infra.id}.railjson.json`);
} catch (e) {
if (e instanceof Error) {
dispatch(
setFailure({
name: e.name,
message: e.message,
})
);
}
dispatch(setFailure(castErrorToFailure(e)));
} finally {
setIsWaiting(false);
}
Expand All @@ -74,16 +65,9 @@ export default function ActionsBar({ infra, isFocused, setIsFocused, inputValue
if (!isWaiting) {
setIsWaiting(true);
try {
await cloneInfra({ infraId: infra.id, name: `${infra.name}_copy` });
await cloneInfra({ infraId: infra.id, name: `${infra.name}_copy` }).unwrap();
} catch (e) {
if (e instanceof Error) {
dispatch(
setFailure({
name: e.name,
message: e.message,
})
);
}
dispatch(setFailure(castErrorToFailure(e)));
} finally {
setIsWaiting(false);
}
Expand All @@ -94,17 +78,10 @@ export default function ActionsBar({ infra, isFocused, setIsFocused, inputValue
if (!isWaiting) {
setIsWaiting(true);
try {
await updateInfra({ infraId: infra.id, body: { name: inputValue } });
await updateInfra({ infraId: infra.id, body: { name: inputValue } }).unwrap();
setIsFocused(undefined);
} catch (e) {
if (e instanceof Error) {
dispatch(
setFailure({
name: e.name,
message: e.message,
})
);
}
dispatch(setFailure(castErrorToFailure(e)));
} finally {
setIsWaiting(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function InfraSelectorEditionActionsBarDelete({

async function handleDeleteInfra() {
try {
await deleteInfra({ infraId: infra.id });
await deleteInfra({ infraId: infra.id }).unwrap();
setRunningDelete(false);
dispatch(
setSuccess({
Expand All @@ -39,9 +39,7 @@ export default function InfraSelectorEditionActionsBarDelete({
dispatch(updateInfraID(undefined));
}
} catch (e) {
if (e instanceof Error) {
dispatch(setFailure(castErrorToFailure(e)));
}
dispatch(setFailure(castErrorToFailure(e)));
}
}

Expand Down
Loading