Files
ChowBox/backend/src/main/java/com/chowbox/config/GlobalExceptionHandler.java

18 lines
557 B
Java
Raw Normal View History

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, "服务器出了点小差,请稍后再试");
}
}