handle fallthrough for JSON parser

This commit is contained in:
Jacob Overgaard
2023-05-26 15:07:17 +02:00
parent a4c8e2617c
commit ede5ad49ce

View File

@@ -66,7 +66,13 @@ export class UmbResourceController extends UmbController {
return {};
} else {
// ApiError - body could hold a ProblemDetailsModel from the server
(error as any).body = typeof error.body === 'string' ? JSON.parse(error.body) : error.body;
if (typeof error.body !== 'undefined' && !!error.body) {
try {
(error as any).body = typeof error.body === 'string' ? JSON.parse(error.body) : error.body;
} catch (e) {
console.error('Error parsing error body (expected JSON)', e);
}
}
// Go through the error status codes and act accordingly
switch (error.status ?? 0) {