Skip to content

Commit 50c6390

Browse files
fix(api.js): fix http.fetch throwing error if response body is empty, closes #2831 (#3008)
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
1 parent c664e9d commit 50c6390

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"api": patch
3+
---
4+
5+
Fix `http.fetch` throwing error if the response is successful but the body is empty.

core/tauri/scripts/bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tooling/api/src/http.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,10 @@ class Client {
203203
// @ts-expect-error
204204
response.data = JSON.parse(response.data as string)
205205
} catch (e) {
206-
if (response.ok) {
206+
if (response.ok && (response.data as unknown as string) === '') {
207+
// @ts-expect-error
208+
response.data = {}
209+
} else if (response.ok) {
207210
throw Error(
208211
`Failed to parse response \`${response.data}\` as JSON: ${e};
209212
try setting the \`responseType\` option to \`ResponseType.Text\` or \`ResponseType.Binary\` if the API does not return a JSON response.`

0 commit comments

Comments
 (0)