From ede5ad49ce5cfefc4953c6bd0df9ac28aa05c1b7 Mon Sep 17 00:00:00 2001 From: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> Date: Fri, 26 May 2023 15:07:17 +0200 Subject: [PATCH] handle fallthrough for JSON parser --- .../src/shared/resources/resource.controller.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Web.UI.Client/src/shared/resources/resource.controller.ts b/src/Umbraco.Web.UI.Client/src/shared/resources/resource.controller.ts index eb4ea54308..3b73d69660 100644 --- a/src/Umbraco.Web.UI.Client/src/shared/resources/resource.controller.ts +++ b/src/Umbraco.Web.UI.Client/src/shared/resources/resource.controller.ts @@ -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) {