View Javadoc
1   package cn.home1.oss.lib.errorhandle.api;
2   
3   import static java.lang.Boolean.FALSE;
4   
5   import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
6   
7   import org.springframework.http.HttpHeaders;
8   
9   /**
10   * Created by zhanghaolun on 16/8/13.
11   */
12  @JsonIgnoreProperties({"cause", "stackTrace", "suppressed"})
13  public class ResolvedErrorException extends RuntimeException {
14  
15    private static final long serialVersionUID = 1L;
16  
17    private final ResolvedError error;
18  
19    public ResolvedErrorException(final ResolvedError error) {
20      super();
21      this.error = error;
22    }
23  
24    public ResolvedError getError() {
25      return this.error;
26    }
27  
28    public static Boolean isResolvedError(final Throwable error) {
29      final Boolean result;
30      if (error != null) {
31        result = ResolvedErrorException.class.isAssignableFrom(error.getClass());
32      } else {
33        result = FALSE;
34      }
35      return result;
36    }
37  
38    public static Boolean isResolvedError(final HttpHeaders headers) {
39      return headers.containsKey(ResolvedError.HEADER_RESOLVED_ERROR);
40    }
41  
42    /**
43     * 判断是否是经过封装过的ResolvedErrorException.
44     *
45     * @param error error
46     * @return boolean boolean
47     */
48    public static Boolean isResolvedErrorWrapByOther(final Throwable error) {
49      final Boolean result;
50      if (error != null && error.getCause() != null) {
51        result = ResolvedErrorException.class.isAssignableFrom(error.getCause().getClass());
52      } else {
53        result = FALSE;
54      }
55      return result;
56    }
57  }