Selaa lähdekoodia

fix(api.js): fix `http.fetch` throwing error if response body is empty, closes #2831 (#3008)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
Amr Bashir 3 vuotta sitten
vanhempi
sitoutus
50c63900c7

+ 5 - 0
.changes/api-fetch-empty-reponse.md

@@ -0,0 +1,5 @@
+---
+"api": patch
+---
+
+Fix `http.fetch` throwing error if the response is successful but the body is empty.

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 0 - 0
core/tauri/scripts/bundle.js


+ 4 - 1
tooling/api/src/http.ts

@@ -203,7 +203,10 @@ class Client {
           // @ts-expect-error
           response.data = JSON.parse(response.data as string)
         } 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(
               `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.`

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä