From 20f4d7b0da76abb409d0d33f8ab99fc493720c23 Mon Sep 17 00:00:00 2001
From: Patrizio Bekerle <patrizio.bekerle@tugraz.at>
Date: Wed, 7 Jul 2021 11:44:28 +0200
Subject: [PATCH] Catch error in case api url of Person entity wasn't found

---
 packages/auth/src/auth-keycloak.js | 37 ++++++++++++++++++------------
 1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/packages/auth/src/auth-keycloak.js b/packages/auth/src/auth-keycloak.js
index 60c3b161..ddca6cb5 100644
--- a/packages/auth/src/auth-keycloak.js
+++ b/packages/auth/src/auth-keycloak.js
@@ -120,23 +120,30 @@ export class AuthKeycloak extends AdapterLitElement {
 
         if (newPerson && this.loadPerson) {
             JSONLD.getInstance(this.entryPointUrl).then((jsonld) => {
-                // find the correct api url for the current person
-                // we are fetching the logged-in person directly to respect the REST philosophy
-                // see: https://github.com/api-platform/api-platform/issues/337
-                const apiUrl = jsonld.getApiUrlForEntityName("Person") + '/' + that.personId;
-
-                fetch(apiUrl, {
-                    headers: {
-                        'Content-Type': 'application/ld+json',
-                        'Authorization': 'Bearer ' + that.token,
-                    },
-                })
-                .then(response => response.json())
-                .then((person) => {
-                    that.person = person;
+                try {
+                    // find the correct api url for the current person
+                    // we are fetching the logged-in person directly to respect the REST philosophy
+                    // see: https://github.com/api-platform/api-platform/issues/337
+                    const apiUrl = jsonld.getApiUrlForEntityName("Person") + '/' + that.personId;
+
+                    fetch(apiUrl, {
+                        headers: {
+                            'Content-Type': 'application/ld+json',
+                            'Authorization': 'Bearer ' + that.token,
+                        },
+                    })
+                        .then(response => response.json())
+                        .then((person) => {
+                            that.person = person;
+                            this.sendSetPropertyEvents();
+                            this._setLoginStatus(this._loginStatus, true);
+                        });
+                } catch (error) {
+                    console.warn(error);
+                    that.person = null;
                     this.sendSetPropertyEvents();
                     this._setLoginStatus(this._loginStatus, true);
-                });
+                }
             }, {}, that.lang);
         }
     }
-- 
GitLab