自动化立体仓库 - WMS系统
lty
3 天以前 d907a822a940c7ec0fb7de0ca845472bda52229b
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
44
45
package com.zy.common.config;
 
import com.core.common.R;
import com.core.exception.CoolException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.method.HandlerMethod;
 
/**
 * Created by vincent on 2019-06-09
 */
@RestControllerAdvice
public class CoolExceptionHandler {
 
    @ExceptionHandler(Exception.class)
    public R handlerException(HandlerMethod handler, Exception e) {
        e.printStackTrace();
        return R.error();
    }
 
    @ExceptionHandler(HttpRequestMethodNotSupportedException.class)
    public R handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) {
        return R.error();
    }
 
    @ExceptionHandler(CoolException.class)
    public R handleRRException(CoolException e) {
        String msg = e.getMessage();
        if (msg != null && msg.contains("|")) {
            String[] split = msg.split("\\|", 2);
            R r = R.error(split[0]);
            r.put("data", split[1]);
            return r;
        }
        String[] split = e.getMessage().split("-");
        if (split.length == 2) {
            if (String.valueOf(split[0]).length() < 3) {
                return R.parse(e.getMessage());
            }
        }
        return R.error(e.getMessage());
    }
 
}