@txstate-mws/sveltekit-utils 1.1.2 → 1.1.3

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/api.js +9 -3
  2. package/package.json +1 -1
package/dist/api.js CHANGED
@@ -83,15 +83,21 @@ export class APIBase {
83
83
  throw error(401);
84
84
  }
85
85
  else {
86
- const message = ((isJsonResponse ? (await rescue(resp.json()))?.message : await rescue(resp.text())) ?? resp.statusText);
87
- toasts.add(message);
86
+ const body = (isJsonResponse ? (await rescue(resp.json())) : await rescue(resp.text())) ?? resp.statusText;
87
+ let message = '';
88
+ if (typeof body === 'string')
89
+ message = body;
90
+ else if (body.message)
91
+ message = body.message;
92
+ else if (body[0]?.message)
93
+ message = body[0].message;
88
94
  throw error(resp.status, message);
89
95
  }
90
96
  }
91
97
  return ((isJsonResponse) ? await resp.json() : await resp.text());
92
98
  }
93
99
  catch (e) {
94
- toasts.add(e.message);
100
+ toasts.add(e.body?.message ?? e.message);
95
101
  throw e;
96
102
  }
97
103
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@txstate-mws/sveltekit-utils",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "Shared library for code that is specifically tied to sveltekit in addition to svelte.",
5
5
  "type": "module",
6
6
  "exports": {