blob: b559634c8364b2515a973ab210ab994e3ad8d1ee (
plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
package org.onap.sdc.dcae.errormng;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.gson.Gson;
import org.springframework.http.HttpStatus;
import org.springframework.web.client.HttpClientErrorException;
public class BaseException extends HttpClientErrorException {
private static Gson gson = new Gson();
protected RequestError requestError;
public RequestError getRequestError() {
return requestError;
}
public void setRequestError(RequestError requestError) {
this.requestError = requestError;
}
public BaseException(HttpClientErrorException theError) {
super(theError.getStatusCode());
String body = theError.getResponseBodyAsString();
if (body != null) {
requestError = extractRequestError(body);
}
}
public BaseException(HttpStatus status, RequestError re){
super(status);
requestError = re;
}
private RequestError extractRequestError(String error) {
ResponseFormat responseFormat = gson.fromJson(error, ResponseFormat.class);
return responseFormat.getRequestError();
}
@JsonIgnore
public String getMessageId() {
return requestError.getMessageId();
}
@JsonIgnore
public String[] getVariables() {
return requestError.getVariables();
}
@JsonIgnore
public String getText(){
return requestError.getText();
}
@Override
@JsonIgnore
public String getMessage() {
return requestError.getFormattedMessage();
}
}
|