better error messages when dynamic client registration fails.

This commit is contained in:
Jason Kulatunga 2023-11-05 10:53:30 -08:00
parent 11386dbf00
commit bba1dde606
No known key found for this signature in database
3 changed files with 26 additions and 12 deletions

View File

@ -199,7 +199,7 @@ func (s *SourceCredential) RegisterDynamicClient() error {
if err == nil {
log.Printf("Error Response body: %s", string(b))
}
return fmt.Errorf("an error occurred while reading dynamic client registration response, status code was not 200: %d", registrationResponse.StatusCode)
return fmt.Errorf("this institution may not support dynamic client registration, meaning that we cannot automatically fetch your records. Please contact support@fastenhealth.com and we'll modify this provider to use our Legacy integration: %d", registrationResponse.StatusCode)
}

View File

@ -32,22 +32,25 @@ func CreateReconnectSource(c *gin.Context) {
logger.Warnf("This client requires a dynamic client registration, starting registration process")
if len(sourceCred.RegistrationEndpoint) == 0 {
logger.Errorln("Empty registration endpoint, cannot be used with dynamic-client registration mode:", sourceCred.DynamicClientRegistrationMode)
c.JSON(http.StatusBadRequest, gin.H{"success": false})
err := fmt.Errorf("this client requires dynamic registration, but does not provide a registration endpoint: %s", sourceCred.DynamicClientRegistrationMode)
logger.Errorln(err)
c.JSON(http.StatusBadRequest, gin.H{"success": false, "error": err.Error()})
return
}
err := sourceCred.RegisterDynamicClient()
if err != nil {
logger.Errorln("An error occurred while registering dynamic client", err)
c.JSON(http.StatusBadRequest, gin.H{"success": false})
err = fmt.Errorf("an error occurred while registering dynamic client: %w", err)
logger.Errorln(err)
c.JSON(http.StatusBadRequest, gin.H{"success": false, "error": err.Error()})
return
}
//generate a JWT token and then use it to get an access token for the dynamic client
err = sourceCred.RefreshDynamicClientAccessToken()
if err != nil {
logger.Errorln("An error occurred while retrieving access token for dynamic client", err)
c.JSON(http.StatusBadRequest, gin.H{"success": false})
err = fmt.Errorf("an error occurred while retrieving access token for dynamic client: %w", err)
logger.Errorln(err)
c.JSON(http.StatusBadRequest, gin.H{"success": false, "error": err.Error()})
return
}
}
@ -56,16 +59,18 @@ func CreateReconnectSource(c *gin.Context) {
//reconnect
err := databaseRepo.UpdateSource(c, &sourceCred)
if err != nil {
logger.Errorln("An error occurred while reconnecting source credential", err)
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
err = fmt.Errorf("an error occurred while reconnecting source credential: %w", err)
logger.Errorln(err)
c.JSON(http.StatusInternalServerError, gin.H{"success": false, "error": err.Error()})
return
}
} else {
//create source for the first time
err := databaseRepo.CreateSource(c, &sourceCred)
if err != nil {
logger.Errorln("An error occurred while storing source credential", err)
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
err = fmt.Errorf("an error occurred while storing source credential: %w", err)
logger.Errorln(err)
c.JSON(http.StatusInternalServerError, gin.H{"success": false, "error": err.Error()})
return
}
}

View File

@ -212,7 +212,7 @@ export class MedicalSourcesConnectedComponent implements OnInit {
const toastNotification = new ToastNotification()
toastNotification.type = ToastType.Error
toastNotification.message = `An error occurred while accessing ${sourceType}: '${JSON.stringify(err)}'`
toastNotification.message = `An error occurred while accessing ${sourceType}: '${this.extractErrorFromResponse(err)}'`
toastNotification.autohide = false
toastNotification.link = {
text: "View Details",
@ -235,6 +235,15 @@ export class MedicalSourcesConnectedComponent implements OnInit {
})
}
extractErrorFromResponse(errResp: any): string {
let errMsg = ""
if(errResp.name == "HttpErrorResponse" && errResp.error && errResp.error?.error){
errMsg = errResp.error.error
} else {
errMsg = JSON.stringify(errResp)
}
return errMsg
}
/**