diff --git a/apps/demo/src/apis/MockSourceApi.ts b/apps/demo/src/apis/MockSourceApi.ts index c5eda7a..5eb409d 100644 --- a/apps/demo/src/apis/MockSourceApi.ts +++ b/apps/demo/src/apis/MockSourceApi.ts @@ -88,4 +88,25 @@ export class MockSourceApi implements SourceApiInterface { ): Promise { throw new Error("Method not implemented."); } + async headSourceImage( + _requestParameters: { id: string }, + _initOverrides?: RequestInit | InitOverrideFunction + ): Promise { + // 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, + }); + } } diff --git a/apps/demo/src/migration-wizard/contexts/discovery-sources/Provider.tsx b/apps/demo/src/migration-wizard/contexts/discovery-sources/Provider.tsx index bffd181..d2386fb 100644 --- a/apps/demo/src/migration-wizard/contexts/discovery-sources/Provider.tsx +++ b/apps/demo/src/migration-wizard/contexts/discovery-sources/Provider.tsx @@ -40,11 +40,24 @@ export const Provider: React.FC = (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(); diff --git a/apps/demo/src/migration-wizard/steps/connect/ConnectStep.tsx b/apps/demo/src/migration-wizard/steps/connect/ConnectStep.tsx index d7766d6..aad81e9 100644 --- a/apps/demo/src/migration-wizard/steps/connect/ConnectStep.tsx +++ b/apps/demo/src/migration-wizard/steps/connect/ConnectStep.tsx @@ -139,6 +139,20 @@ export const ConnectStep: React.FC = () => { /> )} + + {discoverySourcesContext.isDownloadingSource && ( + + The OVA image is downloading + + )} + + + {discoverySourcesContext.errorDownloadingSource && ( + + {discoverySourcesContext.errorDownloadingSource.message} + + )} + ); };