throw and display error messages if Oauth token swap fails -- instead of swallowing error.
This commit is contained in:
parent
f219c53be1
commit
0428766ea6
|
@ -200,8 +200,9 @@ export class MedicalSourcesComponent implements OnInit {
|
||||||
|
|
||||||
if(callbackError && !callbackCode){
|
if(callbackError && !callbackCode){
|
||||||
//TOOD: print this message in the UI
|
//TOOD: print this message in the UI
|
||||||
console.error("an error occurred while authenticating to this source. Please try again later", callbackErrorDescription)
|
let errMsg = "an error occurred while authenticating to this source. Please try again later"
|
||||||
return
|
console.error(errMsg, callbackErrorDescription)
|
||||||
|
throw new Error(errMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("callback code:", callbackCode)
|
console.log("callback code:", callbackCode)
|
||||||
|
@ -210,6 +211,12 @@ export class MedicalSourcesComponent implements OnInit {
|
||||||
let payload: any
|
let payload: any
|
||||||
payload = await this.lighthouseApi.swapOauthToken(sourceType, sourceMetadata,expectedSourceStateInfo, callbackCode)
|
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 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){
|
if(!payload.patient && payload.id_token){
|
||||||
|
@ -290,6 +297,17 @@ export class MedicalSourcesComponent implements OnInit {
|
||||||
console.error(err)
|
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)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,7 @@ export class LighthouseService {
|
||||||
introspection_endpoint: sourceMetadata.introspection_endpoint,
|
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)
|
const params = Oauth.validateAuthResponse(as, client, new URLSearchParams({"code": code, "state": expectedSourceStateInfo.state}), expectedSourceStateInfo.state)
|
||||||
if (Oauth.isOAuth2Error(params)) {
|
if (Oauth.isOAuth2Error(params)) {
|
||||||
console.log('error', params)
|
console.log('error', params)
|
||||||
|
|
Loading…
Reference in New Issue