From 2afc835b7f1ed1d3b717801c0cc14cd51243fd95 Mon Sep 17 00:00:00 2001 From: "Mark H. Wood" Date: Fri, 16 Dec 2022 17:17:55 -0500 Subject: [PATCH] Catch and report errors from non-JSON responses. --- src/app/core/auth/auth.interceptor.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/app/core/auth/auth.interceptor.ts b/src/app/core/auth/auth.interceptor.ts index e55d0c0ff9..672879f436 100644 --- a/src/app/core/auth/auth.interceptor.ts +++ b/src/app/core/auth/auth.interceptor.ts @@ -196,7 +196,24 @@ export class AuthInterceptor implements HttpInterceptor { authStatus.token = new AuthTokenInfo(accessToken); } else { authStatus.authenticated = false; - authStatus.error = isNotEmpty(error) ? ((typeof error === 'string') ? JSON.parse(error) : error) : null; + if (isNotEmpty(error)) { + if (typeof error === 'string') { + try { + authStatus.error = JSON.parse(error); + } catch (e) { + console.error('Unknown auth error "', error, '" caused ', e); + authStatus.error = { + error: 'Unknown', + message: 'Unknown auth error', + status: 500, + timestamp: Date.now(), + path: '' + }; + } + } else { + authStatus.error = error; + } + } } return authStatus; }