当某些操作引发异常时,如何在Spring Boot App中保留CORS标头?例如,在下面的代码中,调用 doSomething(...)
时可能抛出 ItemConflictException@PostMapping("/post-something")
public ResponseEntity<Some> doSomething(@RequestBody String source) {
final Some some = service.doSomehting(source);
return new ResponseEntity<>(url, CORS_HEADERS, HttpStatus.OK);
}
@ResponseStatus(HttpStatus.CONFLICT)
public class ItemConflictException extends RuntimeException {
public ItemConflictException(String message) {
super(message);
}
}
我当然可以在控制器内部引入try / catch,但是也许有更好的可能性?
谢谢