From 87bbba025321a508a0172214a99bad967aa35c68 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Mon, 25 Jul 2022 09:22:06 +0100 Subject: [PATCH] Improve error handling for OIDC discovery and registration --- src/domain/login/LoginViewModel.ts | 7 ++++++- src/domain/login/StartOIDCLoginViewModel.js | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/domain/login/LoginViewModel.ts b/src/domain/login/LoginViewModel.ts index 8853f25f..2b57389a 100644 --- a/src/domain/login/LoginViewModel.ts +++ b/src/domain/login/LoginViewModel.ts @@ -172,7 +172,12 @@ export class LoginViewModel extends ViewModel { new StartOIDCLoginViewModel(this.childOptions({loginOptions: this._loginOptions})) ); this.emitChange("startOIDCLoginViewModel"); - this._startOIDCLoginViewModel.discover(); + try { + await this._startOIDCLoginViewModel.discover(); + } catch (err) { + this._showError(err.message); + this._disposeViewModels(); + } } private _showError(message: string): void { diff --git a/src/domain/login/StartOIDCLoginViewModel.js b/src/domain/login/StartOIDCLoginViewModel.js index 4189e581..70980e32 100644 --- a/src/domain/login/StartOIDCLoginViewModel.js +++ b/src/domain/login/StartOIDCLoginViewModel.js @@ -41,8 +41,18 @@ export class StartOIDCLoginViewModel extends ViewModel { async discover() { // Ask for the metadata once so it gets discovered and cached - await this._api.metadata() - await this._api.registration(); + try { + await this._api.metadata() + } catch (err) { + this.logger.log("Failed to discover OIDC metadata: " + err); + throw new Error("Failed to discover OIDC metadata: " + err.message ); + } + try { + await this._api.registration(); + } catch (err) { + this.logger.log("Failed to register OIDC client: " + err); + throw new Error("Failed to register OIDC client: " + err.message ); + } } async startOIDCLogin() {