21 lines
716 B
Java
21 lines
716 B
Java
package com.xuezhanmaster.common.api;
|
|
|
|
import com.xuezhanmaster.common.exception.BusinessException;
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
|
|
@RestControllerAdvice
|
|
public class GlobalExceptionHandler {
|
|
|
|
@ExceptionHandler(BusinessException.class)
|
|
public ApiResponse<Void> handleBusinessException(BusinessException exception) {
|
|
return ApiResponse.failure(exception.getCode(), exception.getMessage());
|
|
}
|
|
|
|
@ExceptionHandler(Exception.class)
|
|
public ApiResponse<Void> handleGenericException(Exception exception) {
|
|
return ApiResponse.failure("INTERNAL_ERROR", exception.getMessage());
|
|
}
|
|
}
|
|
|