Skip to content

Commit

Permalink
Fix api call to get map
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddasol authored and aeshub committed Jan 3, 2024
1 parent 9269944 commit 5502e53
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions frontend/src/api/ApiCaller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down Expand Up @@ -403,8 +409,8 @@ export class BackendAPICaller {
static async getMap(installationCode: string, mapName: string): Promise<Blob> {
const path: string = 'missions/' + installationCode + '/' + mapName + '/map'

return BackendAPICaller.GET<Response>(path, 'image/png')
.then((response) => response.content.blob())
return BackendAPICaller.GET<Blob>(path, 'image/png')
.then((response) => response.content)
.catch((e) => {
console.error(`Failed to GET /${path}: ` + e)
throw e
Expand Down

0 comments on commit 5502e53

Please sign in to comment.