Skip to content

Commit

Permalink
Http failure handling (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
vigneshwarKV authored Mar 25, 2024
1 parent ce4c4cc commit bee1be3
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

Expand Down Expand Up @@ -117,7 +119,9 @@ public void start(WorkflowModel workflow, TaskModel task, WorkflowExecutor execu
if (response.body != null) {
task.setReasonForIncompletion(response.body.toString());
} else {
task.setReasonForIncompletion("No response from the remote service");
task.setReasonForIncompletion(
Objects.requireNonNullElse(
response.reasonPhrase, "No response from the remote service"));
}
task.setStatus(TaskModel.Status.FAILED);
}
Expand Down Expand Up @@ -175,12 +179,16 @@ protected HttpResponse httpCall(Input input) throws Exception {
if (responseEntity.getStatusCode().is2xxSuccessful() && responseEntity.hasBody()) {
response.body = extractBody(responseEntity.getBody());
}

response.statusCode = responseEntity.getStatusCodeValue();
response.reasonPhrase =
HttpStatus.valueOf(responseEntity.getStatusCode().value()).getReasonPhrase();
response.headers = responseEntity.getHeaders();
return response;
} catch (HttpClientErrorException ex) {
response.headers = ex.getResponseHeaders();
response.statusCode = ex.getStatusCode().value();
response.reasonPhrase = ex.getStatusText();
return response;
} catch (RestClientException ex) {
LOGGER.error(
String.format(
Expand Down

0 comments on commit bee1be3

Please sign in to comment.