1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package fr.cnes.doi.exception;
20
21 import org.restlet.data.Status;
22
23
24
25
26
27
28 public class ClientCrossCiteException extends Exception {
29
30
31
32
33 private static final long serialVersionUID = -246999030222838204L;
34
35
36
37
38 private final String detailMessage;
39
40
41
42
43 private final Status status;
44
45
46
47
48
49
50 public ClientCrossCiteException(final Status status) {
51 super();
52 this.detailMessage = computeDetailMessage(status);
53 this.status = status;
54 }
55
56
57
58
59
60
61
62
63 public ClientCrossCiteException(final Status status,
64 final String message) {
65 super(message);
66 this.detailMessage = computeDetailMessage(status);
67 this.status = status;
68 }
69
70
71
72
73
74
75
76 public ClientCrossCiteException(final Status status,
77 final Throwable cause) {
78 super(cause);
79 this.detailMessage = computeDetailMessage(status);
80 this.status = status;
81 }
82
83
84
85
86
87
88
89
90
91 public ClientCrossCiteException(
92 final Status status,
93 final String message,
94 final Throwable cause) {
95 super(message, cause);
96 this.detailMessage = computeDetailMessage(status);
97 this.status = status;
98 }
99
100
101
102
103
104
105
106 private String computeDetailMessage(final Status status) {
107 final String result;
108 switch (status.getCode()) {
109 case 200:
110 result = "Operation successful";
111 break;
112 case 404:
113 result = "DOI not found";
114 break;
115 case 400:
116 result = "Wrong input parameters";
117 break;
118 default:
119 result = "Internal error";
120 break;
121 }
122 return result;
123 }
124
125
126
127
128
129
130 public Status getStatus() {
131 return this.status;
132 }
133
134
135
136
137
138
139 public String getDetailMessage() {
140 return this.detailMessage;
141 }
142
143 }