mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-12-26 04:03:29 +03:00
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
parent
c664e9dbe0
commit
50c63900c7
5
.changes/api-fetch-empty-reponse.md
Normal file
5
.changes/api-fetch-empty-reponse.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"api": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix `http.fetch` throwing error if the response is successful but the body is empty.
|
File diff suppressed because one or more lines are too long
@ -203,7 +203,10 @@ class Client {
|
|||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
response.data = JSON.parse(response.data as string)
|
response.data = JSON.parse(response.data as string)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (response.ok) {
|
if (response.ok && (response.data as unknown as string) === '') {
|
||||||
|
// @ts-expect-error
|
||||||
|
response.data = {}
|
||||||
|
} else if (response.ok) {
|
||||||
throw Error(
|
throw Error(
|
||||||
`Failed to parse response \`${response.data}\` as JSON: ${e};
|
`Failed to parse response \`${response.data}\` as JSON: ${e};
|
||||||
try setting the \`responseType\` option to \`ResponseType.Text\` or \`ResponseType.Binary\` if the API does not return a JSON response.`
|
try setting the \`responseType\` option to \`ResponseType.Text\` or \`ResponseType.Binary\` if the API does not return a JSON response.`
|
||||||
|
Loading…
Reference in New Issue
Block a user