package com.trafficaudit.common;
|
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.http.HttpStatus;
|
import org.springframework.http.ResponseEntity;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
/** 全局异常处理:把 500 错误原因透出到前端提示(P0:导出失败可见具体原因) */
|
@Slf4j
|
@RestControllerAdvice
|
public class GlobalExceptionHandler {
|
|
@ExceptionHandler(Exception.class)
|
public ResponseEntity<Result<String>> handle(Exception e) {
|
log.error("Unhandled exception", e);
|
String msg = e.getMessage();
|
if (msg == null || msg.trim().isEmpty()) msg = e.toString();
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
.body(Result.error(500, msg));
|
}
|
}
|