[英]POST not supported exception while invoking REST api via SpringBoot
[英]Rest api with intercept of Exception in Springboot
我有一個休息 api:
@RestController
......
@PostMapping(value = "/v1/ms/prop")
public @ResponseBody ResponseEntity<Object> orch(@RequestBody @Valid Request request){
Response response = serv.prop(request);
return ResponseEntity.ok(response);
和 serv.prop(請求):
Response response = new Response ();
try {
calculate(**data**);
callExternalService();
} catch (Exception e) {
**//intercept status error code**
**// writeError(data,errorStatusCode)**
} finally {
writeAuditOperation(auditLog);
MDC.clear();
}
在 catch 內部,我只想在這個 api rest 中攔截錯誤類型(400,404,500,502 ecc ecc)並調用記錄此錯誤的外部服務。
謝謝您的幫助
與其在控制器中手動處理異常,不如嘗試@ExceptionHandler
。
檢查: https ://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.