@gandalan/weblibs 1.1.54 → 1.1.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -52,7 +52,7 @@ export function restClient() {
52
52
  const headers = this.token ? { "Authorization": `Bearer ${this.token}` } : {};
53
53
  const res = await fetch(finalUrl, { method: "GET", headers });
54
54
  if (res.ok)
55
- return await res.json();
55
+ return await this._parseReponse(res);
56
56
  throw new Error(`GET ${finalUrl} failed: ${res.status} ${res.statusText}`);
57
57
  },
58
58
 
@@ -69,7 +69,7 @@ export function restClient() {
69
69
  const headers = this.token ? { "Authorization": `Bearer ${this.token}`, "Content-Type": "application/json" } : {};
70
70
  const res = await fetch(finalUrl, { method: "PUT", body: JSON.stringify(payload), headers });
71
71
  if (res.ok)
72
- return await res.json();
72
+ return await this._parseReponse(res);
73
73
  throw new Error(`PUT ${finalUrl} failed: ${res.status} ${res.statusText}`);
74
74
  },
75
75
 
@@ -86,7 +86,7 @@ export function restClient() {
86
86
  const headers = this.token ? { "Authorization": `Bearer ${this.token}`, "Content-Type": "application/json" } : {};
87
87
  const res = await fetch(finalUrl, { method: "POST", body: JSON.stringify(payload), headers });
88
88
  if (res.ok)
89
- return await res.json();
89
+ return await this._parseReponse(res);
90
90
  throw new Error(`POST ${finalUrl} failed: ${res.status} ${res.statusText}`);
91
91
  },
92
92
 
@@ -102,8 +102,17 @@ export function restClient() {
102
102
  const headers = this.token ? { "Authorization": `Bearer ${this.token}` } : {};
103
103
  const res = await fetch(finalUrl, { method: "DELETE", headers });
104
104
  if (res.ok)
105
- return await res.json();
105
+ return await this._parseReponse(res);
106
106
  throw new Error(`DELETE ${finalUrl} failed: ${res.status} ${res.statusText}`);
107
+ },
108
+
109
+ async _parseReponse(res)
110
+ {
111
+ // check if repsonse is JSON, then return parsed JSON, otherwise return text
112
+ const contentType = res.headers.get("content-type");
113
+ if (contentType && contentType.includes("application/json"))
114
+ return await res.json();
115
+ return await res.text();
107
116
  }
108
117
  };
109
118
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gandalan/weblibs",
3
- "version": "1.1.54",
3
+ "version": "1.1.55",
4
4
  "description": "WebLibs for Gandalan JS/TS/Svelte projects",
5
5
  "keywords": [
6
6
  "gandalan"