From d4b606b51102f1234abacc3bb98117abbbc12419 Mon Sep 17 00:00:00 2001 From: Ian Bolton Date: Wed, 6 Sep 2023 09:01:36 -0400 Subject: [PATCH] :bug: Respond to hub API changes for yaml download (#1329) Updates UI interpretation of hub api routes for downloading reports. For the /applications/:id/analysis endpoint, the API should accept requests with the content type application/x-yaml by setting the accept header to that value in the request. For the /applications/:id/analysis/report endpoint, there is no specific accept header requirement. We can make requests to this endpoint without needing to specify a particular accept header. --- client/src/app/queries/download.ts | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/client/src/app/queries/download.ts b/client/src/app/queries/download.ts index 8efc46faa8..7f6f21a161 100644 --- a/client/src/app/queries/download.ts +++ b/client/src/app/queries/download.ts @@ -13,37 +13,34 @@ export const downloadStaticReport = async ({ applicationId, mimeType, }: DownloadOptions): Promise => { - let acceptHeader = "application/x-tar"; + const yamlAcceptHeader = "application/x-yaml"; + let url = `${APPLICATIONS}/${applicationId}/analysis/report`; switch (mimeType) { case MimeType.YAML: - acceptHeader = "application/x-yaml"; + url = `${APPLICATIONS}/${applicationId}/analysis`; break; case MimeType.TAR: default: - acceptHeader = "application/x-tar"; + url = `${APPLICATIONS}/${applicationId}/analysis/report`; } try { - const response = await axios.get( - `${APPLICATIONS}/${applicationId}/analysis/report`, - { - responseType: "blob", + const response = await axios.get(url, { + responseType: "blob", + ...(MimeType.YAML && { headers: { - Accept: acceptHeader, + Accept: yamlAcceptHeader, }, - } - ); + }), + }); if (response.status !== 200) { throw new Error("Network response was not ok when downloading file."); } const blob = new Blob([response.data]); - saveAs( - blob, - `analysis-report-app-${applicationId}.${acceptHeader.split("-")[1]}` - ); + saveAs(blob, `analysis-report-app-${applicationId}.${mimeType}`); } catch (error) { console.error("There was an error downloading the file:", error); throw error;