//package com.linghu.ExceptionHandler;
|
//
|
//import com.linghu.model.common.ResponseResult;
|
//import org.springframework.http.HttpStatus;
|
//import org.springframework.http.ResponseEntity;
|
//import org.springframework.web.bind.annotation.ExceptionHandler;
|
//import org.springframework.web.bind.annotation.ResponseStatus;
|
//import org.springframework.web.bind.annotation.RestControllerAdvice;
|
//
|
//@RestControllerAdvice
|
//public class GlobalExceptionHandler {
|
//
|
// // 捕获特定的异常,例如 Token 为空的情况
|
// @ExceptionHandler(TokenEmptyException.class)
|
// @ResponseStatus(HttpStatus.BAD_REQUEST)
|
// public ResponseEntity<String> handleTokenEmptyException(TokenEmptyException e) {
|
// // 返回自定义的错误信息
|
// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Token 不能为空");
|
// }
|
//
|
// // 捕获其他全局异常
|
// @ExceptionHandler(Exception.class)
|
// @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
// public ResponseEntity<String> handleGlobalException(Exception e) {
|
// // 返回通用的错误信息
|
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("服务器内部错误: " + e.getMessage());
|
// }
|
//}
|