From 5502e5321f4c8e08f22521b6915c82f70b1b5ac7 Mon Sep 17 00:00:00 2001 From: Eddasol Date: Wed, 3 Jan 2024 13:02:45 +0100 Subject: [PATCH] Fix api call to get map --- frontend/src/api/ApiCaller.tsx | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/frontend/src/api/ApiCaller.tsx b/frontend/src/api/ApiCaller.tsx index 19170232f..5e372f517 100644 --- a/frontend/src/api/ApiCaller.tsx +++ b/frontend/src/api/ApiCaller.tsx @@ -75,9 +75,15 @@ export class BackendAPICaller { var responseContent // Status code 204 means no content if (response.status !== 204) { - responseContent = await response.json().catch((e) => { - throw new Error(`Error getting json from response: ${e}`) - }) + if (contentType === 'image/png') { + responseContent = await response.blob().catch((e) => { + throw new Error(`Error getting blob from response: ${e}`) + }) + } else { + responseContent = await response.json().catch((e) => { + throw new Error(`Error getting json from response: ${e}`) + }) + } } else responseContent = '' return { content: responseContent, headers: response.headers } } @@ -403,8 +409,8 @@ export class BackendAPICaller { static async getMap(installationCode: string, mapName: string): Promise { const path: string = 'missions/' + installationCode + '/' + mapName + '/map' - return BackendAPICaller.GET(path, 'image/png') - .then((response) => response.content.blob()) + return BackendAPICaller.GET(path, 'image/png') + .then((response) => response.content) .catch((e) => { console.error(`Failed to GET /${path}: ` + e) throw e