Skip to content

Commit

Permalink
ECOPROJECT 2333: Adding info about OVA downloading and adding error i…
Browse files Browse the repository at this point in the history
…n UI when creating source not works well (#47)

* Adding error in UI when creating source not works well

Signed-off-by: Montse Ortega <[email protected]>

* Show info about OVA downloading

Signed-off-by: Montse Ortega <[email protected]>

---------

Signed-off-by: Montse Ortega <[email protected]>
  • Loading branch information
ammont82 authored Nov 27, 2024
1 parent 248c3e1 commit 20b797d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
21 changes: 21 additions & 0 deletions apps/demo/src/apis/MockSourceApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,25 @@ export class MockSourceApi implements SourceApiInterface {
): Promise<Source> {
throw new Error("Method not implemented.");
}
async headSourceImage(
_requestParameters: { id: string },
_initOverrides?: RequestInit | InitOverrideFunction
): Promise<Response> {
// Different scenarios
const errorScenarios = [
{ status: 404, statusText: "Not Found" },
{ status: 500, statusText: "Internal Server Error" },
{ status: 403, statusText: "Forbidden" },
{ status: 401, statusText: "Unautorized" },
];

// Choose one option randomly
const randomError = errorScenarios[Math.floor(Math.random() * errorScenarios.length)];

// Simulation of error response
return new Response(null, {
status: randomError.status,
statusText: randomError.statusText,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,24 @@ export const Provider: React.FC<PropsWithChildren> = (props) => {
anchor.download = sourceName + ".ova";

const newSource = await createSource(sourceName, sourceSshKey);
const imageUrl = `/planner/api/v1/sources/${newSource.id}/image`;

const response = await fetch(imageUrl, { method: 'HEAD' });

if (!response.ok) {
const error: Error = new Error(`Error downloading source: ${response.status} ${response.statusText}`);
downloadSourceState.error = error;
console.error("Error downloading source:", error);
throw error;
}
else {
downloadSourceState.loading = true;
}
// TODO(jkilzi): See: ECOPROJECT-2192.
// Then don't forget to remove the '/planner/' prefix in production.
// const image = await sourceApi.getSourceImage({ id: newSource.id }); // This API is useless in production
// anchor.href = URL.createObjectURL(image); // Don't do this...
anchor.href = `/planner/api/v1/sources/${newSource.id}/image`;
anchor.href = imageUrl;

document.body.appendChild(anchor);
anchor.click();
Expand Down
14 changes: 14 additions & 0 deletions apps/demo/src/migration-wizard/steps/connect/ConnectStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,20 @@ export const ConnectStep: React.FC = () => {
/>
)}
</StackItem>
<StackItem>
{discoverySourcesContext.isDownloadingSource && (
<Alert isInline variant="info" title="Download OVA image">
The OVA image is downloading
</Alert>
)}
</StackItem>
<StackItem>
{discoverySourcesContext.errorDownloadingSource && (
<Alert isInline variant="danger" title="Download Source error">
{discoverySourcesContext.errorDownloadingSource.message}
</Alert>
)}
</StackItem>
</Stack>
);
};
Expand Down

0 comments on commit 20b797d

Please sign in to comment.