huliguo
2 天以前 580d70b15ae47bc180a0b579af8c47c506eefac6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//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());
//    }
//}