I am having difficulties figuring out how to add a custom 500 error message for an exception.
When the response has the status of Internal Server Error, I receive a backend response that looks like this:
errors: [
0: {
errorCode: null
exceptionMessage: null
language: null
message: "BAPIException with type: E id: messageNumber: 000 message: Keine Barcodedaten gefunden (ZPORH_BARCODELISTE_CSV)"
position: null
reason: null
subject: null
subjectType: null,
type: "BWPErpIntegrationBapiError"
}
]
My internal server handler looks like this so far:
responseStatus = HttpResponseStatus.INTERNAL_SERVER_ERROR;
// tslint:disable-next-line:variable-name
handleError(_request: HttpRequest<any>, response: HttpErrorResponse): void {
if (response.status === this.responseStatus) {
// console.log(response.error);
if (response.error?.type === 'BWPErpIntegrationBapiError') {
this.globalMessageService.add(
response.error?.message,
GlobalMessageType.MSG_TYPE_ERROR
);
} else {
// console.log(response.status);
this.globalMessageService.add(
{ key: 'httpHandlers.internalServerError' },
GlobalMessageType.MSG_TYPE_ERROR
);
}
}
}
The problem I am facing is that the response I get from the backend is not the same as the HttpErrorResponse from Angular, and I do not know how to approach this problem.
I tried to extend the HttpErrorResponse and add an errors property that has that array with values and create an interceptor for it but console logging the response.errors[0] was always null.
Also the way I get this BWPErpIntegrationBapiError exception is by trying to download and CSV that also has a response.error value of Blob.
Any help would be appreciated!