Cześć,
mam w kontrolerze metodę która zwraca dokument Word:
@RequestMapping(method = RequestMethod.GET, produces = "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
@ResponseBody
public ResponseEntity<Resource> getFile() {
Resource file = storageService.loadTemplateResource();
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + file.getFilename() + "\"")
.body(file);
}
Jednak kiedy storageService.loadTemplateResource()
rzuca wyjątek, metoda zwraca puste body.
W jaki sposób mogę zwrócić springowy komunikat o błędzię (w formacie text/plain i application/json)?
Zauważyłem że po usunięciu produces = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
z @RequestMapping
komunikat jest zwracany poprawnie.