@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.
- package/dist/api.js +9 -3
- 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
|
|
87
|
-
|
|
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
|
}
|