Commit 637b7f41c31123ce41635d2dd35a2d6b7dbed8dc
1 parent
2e70d82c
Exists in
master
optimized ResultInfoException
Showing
2 changed files
with
90 additions
and
13 deletions
Show diff stats
src/main/java/com/taover/util/bean/ResultInfoException.java
0 → 100644
... | ... | @@ -0,0 +1,41 @@ |
1 | +package com.taover.util.bean; | |
2 | + | |
3 | +public class ResultInfoException extends Exception { | |
4 | + private static final long serialVersionUID = 1L; | |
5 | + | |
6 | + private String code; | |
7 | + private String error; | |
8 | + private Object data; | |
9 | + | |
10 | + private ResultInfoException(){} | |
11 | + | |
12 | + protected ResultInfoException(String code, String error, Object data){ | |
13 | + this.code = code; | |
14 | + this.error = error; | |
15 | + this.data = data; | |
16 | + } | |
17 | + | |
18 | + public String getCode() { | |
19 | + return code; | |
20 | + } | |
21 | + | |
22 | + public void setCode(String code) { | |
23 | + this.code = code; | |
24 | + } | |
25 | + | |
26 | + public String getError() { | |
27 | + return error; | |
28 | + } | |
29 | + | |
30 | + public void setError(String error) { | |
31 | + this.error = error; | |
32 | + } | |
33 | + | |
34 | + public Object getData() { | |
35 | + return data; | |
36 | + } | |
37 | + | |
38 | + public void setData(Object data) { | |
39 | + this.data = data; | |
40 | + } | |
41 | +} | ... | ... |
src/main/java/com/taover/util/bean/UtilResultInfo.java
1 | 1 | package com.taover.util.bean; |
2 | 2 | |
3 | 3 | public class UtilResultInfo { |
4 | - public static final String SUCCESS ="success"; | |
4 | + public static final String OK ="ok"; | |
5 | 5 | public static final String FAIL ="fail"; |
6 | 6 | public static final String NOT_AUTHORIZED ="not_authorized"; |
7 | 7 | |
8 | - public static ResultInfo getResultFailure(String error){ | |
9 | - return getResult(UtilResultInfo.FAIL, error, null); | |
8 | + public static ResultInfo getFailure(String error){ | |
9 | + return getResultInfo(UtilResultInfo.FAIL, error, null); | |
10 | 10 | } |
11 | 11 | |
12 | 12 | public static ResultInfo getResultFailure(String error, Object data){ |
13 | - return getResult(UtilResultInfo.FAIL, error, data); | |
13 | + return getResultInfo(UtilResultInfo.FAIL, error, data); | |
14 | 14 | } |
15 | 15 | |
16 | - public static ResultInfo getResultSuccess(String error){ | |
17 | - return getResult(UtilResultInfo.SUCCESS, error, null); | |
16 | + public static ResultInfo getSuccess(String error){ | |
17 | + return getResultInfo(UtilResultInfo.OK, error, null); | |
18 | 18 | } |
19 | 19 | |
20 | - public static ResultInfo getResultSuccess(String error, Object data){ | |
21 | - return getResult(UtilResultInfo.SUCCESS, error, data); | |
20 | + public static ResultInfo getSuccess(String error, Object data){ | |
21 | + return getResultInfo(UtilResultInfo.OK, error, data); | |
22 | 22 | } |
23 | 23 | |
24 | - public static ResultInfo getResultNotAuthorized(String error){ | |
25 | - return getResult(UtilResultInfo.NOT_AUTHORIZED, error, null); | |
24 | + public static ResultInfo getNotAuthorized(String error){ | |
25 | + return getResultInfo(UtilResultInfo.NOT_AUTHORIZED, error, null); | |
26 | 26 | } |
27 | 27 | |
28 | - public static ResultInfo getResultNotAuthorized(String error, Object data){ | |
29 | - return getResult(UtilResultInfo.NOT_AUTHORIZED, error, data); | |
28 | + public static ResultInfo getNotAuthorized(String error, Object data){ | |
29 | + return getResultInfo(UtilResultInfo.NOT_AUTHORIZED, error, data); | |
30 | 30 | } |
31 | 31 | |
32 | - public static ResultInfo getResult(String code, String error, Object data){ | |
32 | + public static ResultInfo getResultInfo(String code, String error, Object data){ | |
33 | 33 | return new ResultInfo(code, error, data); |
34 | 34 | } |
35 | + | |
36 | + public static ResultInfoException getExceptionFailure(String error){ | |
37 | + return getResultInfoException(UtilResultInfo.FAIL, error, null); | |
38 | + } | |
39 | + | |
40 | + public static ResultInfoException getExceptionFailure(String error, Object data){ | |
41 | + return getResultInfoException(UtilResultInfo.FAIL, error, data); | |
42 | + } | |
43 | + | |
44 | + public static ResultInfoException getExceptionSuccess(String error){ | |
45 | + return getResultInfoException(UtilResultInfo.OK, error, null); | |
46 | + } | |
47 | + | |
48 | + public static ResultInfoException getExceptionSuccess(String error, Object data){ | |
49 | + return getResultInfoException(UtilResultInfo.OK, error, data); | |
50 | + } | |
51 | + | |
52 | + public static ResultInfoException getExceptionNotAuthorized(String error){ | |
53 | + return getResultInfoException(UtilResultInfo.NOT_AUTHORIZED, error, null); | |
54 | + } | |
55 | + | |
56 | + public static ResultInfoException getExceptionNotAuthorized(String error, Object data){ | |
57 | + return getResultInfoException(UtilResultInfo.NOT_AUTHORIZED, error, data); | |
58 | + } | |
59 | + | |
60 | + public static ResultInfoException getResultInfoException(String code, String error, Object data){ | |
61 | + return new ResultInfoException(code, error, data); | |
62 | + } | |
63 | + | |
64 | + public static ResultInfoException getExceptionFromResultInfo(ResultInfo result){ | |
65 | + return getResultInfoException(result.getCode(), result.getCode(), result.getData()); | |
66 | + } | |
67 | + | |
68 | + public static ResultInfo getResultInfoFromException(ResultInfoException exception){ | |
69 | + return getResultInfo(exception.getCode(), exception.getError(), exception.getData()); | |
70 | + } | |
35 | 71 | } | ... | ... |