Fix for upload parameters and api client handling of empty responses. AWS put returns no body on a 200 so response.json would mistakenly throw an error

This commit is contained in:
Dean 2025-01-02 15:26:50 +00:00
parent 2ff1c7ad28
commit a7be765bf1
2 changed files with 11 additions and 5 deletions

View File

@ -88,12 +88,12 @@
})
loading = true
try {
const res = await API.externalUpload({
const res = await API.externalUpload(
datasourceId,
bucket,
key: processedFileKey,
data,
})
processedFileKey,
data
)
notificationStore.actions.success("File uploaded successfully")
loading = false
return res

View File

@ -163,7 +163,13 @@ export const createAPIClient = (config: APIClientConfig = {}): APIClient => {
} else if (parseResponse) {
return await parseResponse(response)
} else {
return (await response.json()) as ResponseT
const text = await response.text()
// If the response has no body at all e.g s3.put
if (!text) {
// Empty response
return {} as ResponseT
}
return JSON.parse(text) as ResponseT
}
} catch (error) {
delete cache[url]