I have a web application with Springboot and Angular 6.
A response entity with a detailed error message does not show the right error in Angular (instead of "Invalid Excel file" displays "Http failure response for http://localhost:8081/api/v1/activities/excel/import: 500 OK")
Controller's code:
...
@PostMapping("/activities/excel/import")
public ResponseEntity<?> import(...) {
return new ResponseEntity<> ("Invalid Excel file", HttpStatus.BAD_REQUEST);
}
...
UI (Angular 6):
importFromExcel() {
this.activityService.importFromExcel(this.file).subscribe(
(result) => {...},
(error) => {
console.log (error.error) //displays undefined
console.log (error.name) //displays undefined
console.log (error.message) //displays undefined
console.log(JSON.stringify(error)) //displays Http failure response for http://localhost:8081/api/v1/activities/excel/import: 500 OK
}
)
}
How can I retrieve the HTTP response body?
PROBLEM SOLVED
An interceptor (which have been added in other parts of the code) was handling error messages from backend in an incomplete way. As a result in some places in the app (like my example) the error messages were no longer displayed. Problem identified :).