throw and display error messages if Oauth token swap fails -- instead of swallowing error.

This commit is contained in:
Jason Kulatunga 2023-01-16 21:40:32 -08:00
parent f219c53be1
commit 0428766ea6
2 changed files with 21 additions and 3 deletions

View File

@ -200,8 +200,9 @@ export class MedicalSourcesComponent implements OnInit {
if(callbackError && !callbackCode){
//TOOD: print this message in the UI
console.error("an error occurred while authenticating to this source. Please try again later", callbackErrorDescription)
return
let errMsg = "an error occurred while authenticating to this source. Please try again later"
console.error(errMsg, callbackErrorDescription)
throw new Error(errMsg)
}
console.log("callback code:", callbackCode)
@ -210,6 +211,12 @@ export class MedicalSourcesComponent implements OnInit {
let payload: any
payload = await this.lighthouseApi.swapOauthToken(sourceType, sourceMetadata,expectedSourceStateInfo, callbackCode)
if(!payload.access_token || payload.error){
//if the access token is not set, then something is wrong,
let errMsg = payload.error || "unable to retrieve access_token"
console.error(errMsg)
throw new Error(errMsg)
}
//If payload.patient is not set, make sure we extract the patient ID from the id_token or make an introspection req
if(!payload.patient && payload.id_token){
@ -290,6 +297,17 @@ export class MedicalSourcesComponent implements OnInit {
console.error(err)
});
})
.catch((err) => {
delete this.status[sourceType]
// window.location.reload();
const toastNotification = new ToastNotification()
toastNotification.type = ToastType.Error
toastNotification.message = `An error occurred while accessing ${sourceType}: ${err}`
toastNotification.autohide = false
this.toastService.show(toastNotification)
console.error(err)
})
}

View File

@ -146,7 +146,7 @@ export class LighthouseService {
introspection_endpoint: sourceMetadata.introspection_endpoint,
}
console.log("STARTING--- Oauth.validateAuthResponse")
console.log("STARTING--- Oauth.validateAuthResponse", as)
const params = Oauth.validateAuthResponse(as, client, new URLSearchParams({"code": code, "state": expectedSourceStateInfo.state}), expectedSourceStateInfo.state)
if (Oauth.isOAuth2Error(params)) {
console.log('error', params)