Skip to content

Commit

Permalink
refactor: remove unused argument and add new private constant
Browse files Browse the repository at this point in the history
  • Loading branch information
tribiec committed Mar 21, 2024
1 parent 53bed13 commit 1d7f31f
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions src/main/java/cl/transbank/util/HttpUtilImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class HttpUtilImpl implements HttpUtil {
private static Logger logger = Logger.getLogger(HttpUtilImpl.class.getName());

private static volatile HttpUtilImpl instance;
private static final String ERROR_MESSAGE = "error_message";

@Setter
@Getter(AccessLevel.PRIVATE)
Expand All @@ -45,7 +46,7 @@ public <T> T request(
Class<T> clazz
) throws IOException, WebpayException {
final String jsonIn = getJsonUtil().jsonEncode(request);
final String jsonOut = request(url, method, jsonIn, headers, true);
final String jsonOut = request(url, method, jsonIn, headers);
return getJsonUtil().jsonDecode(jsonOut, clazz);
}

Expand All @@ -57,7 +58,7 @@ public <T> List<T> requestList(
Class<T[]> clazz
) throws IOException, WebpayException {
final String jsonIn = getJsonUtil().jsonEncode(request);
final String jsonOut = request(url, method, jsonIn, headers, true);
final String jsonOut = request(url, method, jsonIn, headers);
return getJsonUtil().jsonDecodeToList(jsonOut, clazz);
}

Expand Down Expand Up @@ -105,21 +106,6 @@ public String request(
return request(url, method, query, null, headers);
}

/**
* Sends a HTTP request and returns the response.
* This method uses the provided URL and request method to send the request.
* It uses default headers, a default response type, and does not send a request body.
*/
public String request(
@NonNull URL url,
RequestMethod method,
String query,
Map<String, String> headers,
boolean useException
) throws IOException, WebpayException {
return request(url, method, query, null, headers);
}

/**
* Sends a HTTP request and returns the response.
* This method uses the provided URL to send the request.
Expand Down Expand Up @@ -232,7 +218,7 @@ private void handleResponse(
final Map<String, Object> errorMap = (Map<String, Object>) getJsonUtil()
.jsonDecode(responseBody, HashMap.class);

errorMessage = errorMap.get("error_message");
errorMessage = errorMap.get(ERROR_MESSAGE);
}

if (null == errorMessage) errorMessage =
Expand All @@ -246,10 +232,9 @@ private void handleResponse(
if (responseBody != null && !responseBody.trim().startsWith("[")) {
final Map tempMap = getJsonUtil().jsonDecode(responseBody, HashMap.class);
if (
tempMap.containsKey("error_message") &&
tempMap.get("error_message") != null
tempMap.containsKey(ERROR_MESSAGE) && tempMap.get(ERROR_MESSAGE) != null
) {
throw new WebpayException(tempMap.get("error_message").toString());
throw new WebpayException(tempMap.get(ERROR_MESSAGE).toString());
}
}
}
Expand Down

0 comments on commit 1d7f31f

Please sign in to comment.