地质所 沉降监测网建设项目
chenhuan
2024-05-16 0fdd42e318f51f9e3c6581473416af1cca69877f
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.javaweb.app.common.exception;
 
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
 
import com.javaweb.app.common.page.ResultData;
 
/**
 * <p>File:GloablExceptionHandler.java</p>
 * <p>Title: </p>
 * <p>Description:</p>
 * <p>Copyright: Copyright (c) 2018 2018年11月29日 下午6:34:26</p>
 * <p>Company:  </p>
 * @author zmr
 * @version 1.0
 */
@ControllerAdvice
public class GloablExceptionHandler
{
    @ResponseBody
    @ExceptionHandler(Exception.class)
    public ResultData handleException(Exception e)
    {
        String msg = e.getMessage();
        if (msg == null || msg.equals(""))
        {
            msg = "服务器出错";
        }
        return new ResultData(500, msg);
    }
 
    // 捕捉UnauthorizedException
    @ResponseBody
    @ResponseStatus(HttpStatus.UNAUTHORIZED)
    @ExceptionHandler(UnauthorizedException.class)
    public ResultData handle401()
    {
        return new ResultData(401, "Unauthorized");
    }
}