@mkja/o-data 0.0.4 → 0.0.5

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.
Files changed (2) hide show
  1. package/dist/index.js +6 -18
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -91,13 +91,7 @@ export class OdataClient {
91
91
  result: { error },
92
92
  };
93
93
  }
94
- let result;
95
- try {
96
- result = await response.json();
97
- }
98
- catch {
99
- result = {};
100
- }
94
+ const result = response.status === 204 ? {} : await response.json();
101
95
  return {
102
96
  ok: true,
103
97
  status: response.status,
@@ -144,7 +138,7 @@ class CollectionOperation {
144
138
  const url = this.buildUrl(queryString);
145
139
  const request = new Request(url);
146
140
  const response = await this.#options.transport(request);
147
- const data = await response.json();
141
+ const data = response.status === 204 || response.status === 304 ? {} : await response.json();
148
142
  return {
149
143
  ok: response.ok,
150
144
  status: response.status,
@@ -168,7 +162,7 @@ class CollectionOperation {
168
162
  async create(c, o) {
169
163
  const request = buildCreateRequest(this.#path, c, o, this.#options.baseUrl, this.#entityset, this.#schema);
170
164
  const response = await this.#options.transport(request);
171
- const data = await response.json();
165
+ const data = response.status === 204 ? {} : await response.json();
172
166
  return {
173
167
  ok: response.ok,
174
168
  status: response.status,
@@ -223,7 +217,7 @@ class SingleOperation {
223
217
  const url = this.buildUrl(queryString);
224
218
  const request = new Request(url);
225
219
  const response = await this.#options.transport(request);
226
- const data = await response.json();
220
+ const data = response.status === 204 || response.status === 304 ? {} : await response.json();
227
221
  return {
228
222
  ok: response.ok,
229
223
  status: response.status,
@@ -247,7 +241,7 @@ class SingleOperation {
247
241
  async update(u, o) {
248
242
  const request = buildUpdateRequest(this.#path, u, o, this.#options.baseUrl, this.#entityset, this.#schema);
249
243
  const response = await this.#options.transport(request);
250
- const data = await response.json();
244
+ const data = response.status === 204 ? {} : await response.json();
251
245
  return {
252
246
  ok: response.ok,
253
247
  status: response.status,
@@ -366,13 +360,7 @@ class SingleOperation {
366
360
  result: { error },
367
361
  };
368
362
  }
369
- let result;
370
- try {
371
- result = await response.json();
372
- }
373
- catch {
374
- result = {};
375
- }
363
+ const result = response.status === 204 ? {} : await response.json();
376
364
  return {
377
365
  ok: true,
378
366
  status: response.status,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mkja/o-data",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/m-kj-aldrin/o-data"