23
23
import com .adyen .Config ;
24
24
import com .adyen .Service ;
25
25
import com .adyen .constants .ApiConstants ;
26
- import com .adyen .enums .Environment ;
27
26
import com .adyen .httpclient .ClientInterface ;
28
27
import com .adyen .httpclient .HTTPClientException ;
29
28
import com .adyen .model .ApiError ;
30
29
import com .adyen .model .RequestOptions ;
31
30
import com .adyen .service .exception .ApiException ;
32
- import com .fasterxml .jackson .core .JacksonException ;
33
- import com .fasterxml .jackson .databind .exc .MismatchedInputException ;
34
- import com .google .gson .Gson ;
35
31
36
32
import java .io .IOException ;
37
33
import java .util .List ;
@@ -97,14 +93,14 @@ public String request(String json, RequestOptions requestOptions, ApiConstants.H
97
93
/**
98
94
* Request using json String with additional request parameters like idempotency-key
99
95
*
100
- * @param json json
96
+ * @param json body of the request
101
97
* @param requestOptions request options
102
98
* @param httpMethod http method
103
99
* @param pathParams path parameters
104
100
* @param queryString query string parameters
105
- * @throws ApiException apiException
106
- * @throws IOException IOException
107
- * @return request
101
+ * @throws ApiException apiException when an API error is returned
102
+ * @throws IOException IOException when an unexpected error occurs
103
+ * @return JSON response
108
104
*/
109
105
public String request (String json , RequestOptions requestOptions , ApiConstants .HttpMethod httpMethod , Map <String , String > pathParams , Map <String , String > queryString ) throws ApiException , IOException {
110
106
ClientInterface clientInterface = service .getClient ().getHttpClient ();
@@ -113,12 +109,19 @@ public String request(String json, RequestOptions requestOptions, ApiConstants.H
113
109
try {
114
110
return clientInterface .request (resolve (pathParams ), json , config , service .isApiKeyRequired (), requestOptions , httpMethod , queryString );
115
111
} catch (HTTPClientException e ) {
116
- apiException = new ApiException (e .getMessage (), e .getCode (), e .getResponseHeaders ());
117
- apiException .setResponseBody (e .getResponseBody ());
118
112
try {
119
- apiException .setError (ApiError .fromJson (e .getResponseBody ()));
113
+ // build ApiException
114
+ ApiError apiError = ApiError .fromJson (e .getResponseBody ());
115
+ String message = apiError .getMessage () + " ErrorCode: " + apiError .getErrorCode ();
116
+
117
+ apiException = new ApiException (message , e .getCode (), e .getResponseHeaders ());
118
+ apiException .setResponseBody (e .getResponseBody ());
119
+ apiException .setError (apiError );
120
+
120
121
} catch (Exception ignore ) {
121
122
// Response body could not be parsed (e.g. not JSON), raw response body available in ApiException#responseBody
123
+ apiException = new ApiException (e .getMessage (), e .getCode (), e .getResponseHeaders ());
124
+ apiException .setResponseBody (e .getResponseBody ());
122
125
}
123
126
}
124
127
throw apiException ;
0 commit comments