make sure we correctly extract error message fields.

This commit is contained in:
Jason Kulatunga 2024-01-29 16:36:54 -08:00
parent 947f0251dd
commit 8ee98845cc
No known key found for this signature in database
1 changed files with 17 additions and 3 deletions

View File

@ -253,7 +253,7 @@ export class MedicalSourcesConnectedComponent implements OnInit {
} }
errData.error_data = { errData.error_data = {
summary: toastNotification.message, summary: toastNotification.message,
error: JSON.stringify(err), error: JSON.stringify(err, this.replaceErrors),
stack: err.stack stack: err.stack
} }
@ -262,17 +262,31 @@ export class MedicalSourcesConnectedComponent implements OnInit {
}) })
} }
//https://stackoverflow.com/a/18391400/1157633
extractErrorFromResponse(errResp: any): string { extractErrorFromResponse(errResp: any): string {
let errMsg = "" let errMsg = ""
if(errResp.name == "HttpErrorResponse" && errResp.error && errResp.error?.error){ if(errResp.name == "HttpErrorResponse" && errResp.error && errResp.error?.error){
errMsg = errResp.error.error errMsg = errResp.error.error
} else { } else {
errMsg = JSON.stringify(errResp) errMsg = JSON.stringify(errResp, this.replaceErrors)
} }
return errMsg return errMsg
} }
//stringify error objects
replaceErrors(key, value) {
if (value instanceof Error) {
var error = {};
Object.getOwnPropertyNames(value).forEach(function (propName) {
error[propName] = value[propName];
});
return error;
}
return value;
}
/** /**
* https://github.com/smart-on-fhir/client-js/blob/8f64b770dbcd0abd30646e239cd446dfa4d831f6/src/lib.ts#L311 * https://github.com/smart-on-fhir/client-js/blob/8f64b770dbcd0abd30646e239cd446dfa4d831f6/src/lib.ts#L311