swell-js 3.23.3 → 3.24.0

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.
@@ -130,7 +130,7 @@ const options = {
130
130
  };
131
131
 
132
132
  const api = {
133
- version: '3.23.3',
133
+ version: '3.24.0',
134
134
  options,
135
135
  request,
136
136
 
@@ -227,7 +227,8 @@ async function request(
227
227
 
228
228
  const session = allOptions.session || allOptions.getCookie('swell-session');
229
229
  const locale = allOptions.locale || allOptions.getCookie('swell-locale');
230
- const currency = allOptions.currency || allOptions.getCookie('swell-currency');
230
+ const currency =
231
+ allOptions.currency || allOptions.getCookie('swell-currency');
231
232
  const path = allOptions.path || '/api';
232
233
 
233
234
  const baseUrl = `${allOptions.url}${allOptions.base || ''}${path}`;
@@ -288,10 +289,21 @@ async function request(
288
289
  allOptions.setCookie('swell-session', responseSession);
289
290
  }
290
291
 
291
- const result = await response.json();
292
+ // Response could be text, json, or empty
293
+ let result = null;
294
+ try {
295
+ result = await response.text();
296
+ try {
297
+ result = JSON.parse(result);
298
+ } catch (err) {
299
+ // noop
300
+ }
301
+ } catch (err) {
302
+ // noop
303
+ }
292
304
 
293
305
  if (result && result.error) {
294
- const err = new Error(result.error.message);
306
+ const err = new Error(result.error.message || result.error);
295
307
  err.status = response.status;
296
308
  err.code = result.error.code;
297
309
  err.param = result.error.param;
package/dist/api.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { a as default } from './api.2d3371be.mjs';
1
+ export { a as default } from './api.6ceb5c2c.mjs';
2
2
  import './card.982ad378.mjs';
3
3
  import './index.b29eadc6.mjs';
4
4
  import 'qs';
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { a as default } from './api.2d3371be.mjs';
1
+ export { a as default } from './api.6ceb5c2c.mjs';
2
2
  import './card.982ad378.mjs';
3
3
  import './index.b29eadc6.mjs';
4
4
  import 'qs';
package/dist/swell.cjs CHANGED
@@ -9965,7 +9965,7 @@ const options = {
9965
9965
  };
9966
9966
 
9967
9967
  const api = {
9968
- version: '3.23.3',
9968
+ version: '3.24.0',
9969
9969
  options,
9970
9970
  request,
9971
9971
 
@@ -10062,7 +10062,8 @@ async function request(
10062
10062
 
10063
10063
  const session = allOptions.session || allOptions.getCookie('swell-session');
10064
10064
  const locale = allOptions.locale || allOptions.getCookie('swell-locale');
10065
- const currency = allOptions.currency || allOptions.getCookie('swell-currency');
10065
+ const currency =
10066
+ allOptions.currency || allOptions.getCookie('swell-currency');
10066
10067
  const path = allOptions.path || '/api';
10067
10068
 
10068
10069
  const baseUrl = `${allOptions.url}${allOptions.base || ''}${path}`;
@@ -10123,10 +10124,21 @@ async function request(
10123
10124
  allOptions.setCookie('swell-session', responseSession);
10124
10125
  }
10125
10126
 
10126
- const result = await response.json();
10127
+ // Response could be text, json, or empty
10128
+ let result = null;
10129
+ try {
10130
+ result = await response.text();
10131
+ try {
10132
+ result = JSON.parse(result);
10133
+ } catch (err) {
10134
+ // noop
10135
+ }
10136
+ } catch (err) {
10137
+ // noop
10138
+ }
10127
10139
 
10128
10140
  if (result && result.error) {
10129
- const err = new Error(result.error.message);
10141
+ const err = new Error(result.error.message || result.error);
10130
10142
  err.status = response.status;
10131
10143
  err.code = result.error.code;
10132
10144
  err.param = result.error.param;