18 lines
557 B
Java
18 lines
557 B
Java
|
|
package com.chowbox.config;
|
||
|
|
|
||
|
|
import com.chowbox.model.ApiResponse;
|
||
|
|
import lombok.extern.slf4j.Slf4j;
|
||
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||
|
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||
|
|
|
||
|
|
@Slf4j
|
||
|
|
@RestControllerAdvice
|
||
|
|
public class GlobalExceptionHandler {
|
||
|
|
|
||
|
|
@ExceptionHandler(Exception.class)
|
||
|
|
public ApiResponse<?> handleException(Exception e) {
|
||
|
|
log.error("Unhandled exception: {}", e.getMessage(), e);
|
||
|
|
return ApiResponse.fail(500, "服务器出了点小差,请稍后再试");
|
||
|
|
}
|
||
|
|
}
|