Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(connect): add http connector response error handling #4447

Conversation

Nandanrshenoy
Copy link
Contributor

@Nandanrshenoy Nandanrshenoy commented Jun 21, 2024

Contribution towards Camunda HTTP Connector enhancement for 4XX and 5XX errors

related to #4241

…error handling enhancement for 4XX and 5XX errors

Contribution towards Camunda HTTP Connector enhancement for 4XX and 5XX errors -GIT Issue 4241 

Signed-off-by: Shenoy, Nandan <[email protected]>
…ror handling enhancement for 4XX and 5XX errors

 Contribution towards Camunda HTTP Connector enhancement for 4XX and 5XX errors -GIT Issue 4241

Signed-off-by: Shenoy, Nandan <[email protected]>
…handling enhancement for 4XX and 5XX errors

Contribution towards Camunda HTTP Connector enhancement for 4XX and 5XX errors -GIT Issue 4241 

Signed-off-by: Shenoy, Nandan <[email protected]>
…handling enhancement for 4XX and 5XX errors

Contribution towards Camunda HTTP Connector enhancement for 4XX and 5XX errors -GIT Issue 4241

Signed-off-by: Shenoy, Nandan <[email protected]>
@Nandanrshenoy
Copy link
Contributor Author

@danielkelemen ,
Requesting your support to help review this PR.

Thanks and Regards,
Nandan Shenoy

Copy link
Member

@danielkelemen danielkelemen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Nandanrshenoy, Thanks for the PR!

👍 It looks pretty nice and thank you for adding tests, too.
🔧 I added a few suggestions to separate the http error response from communication errors.
🔧 Code formatting is off at several places. Could you reformat the code according to our style guidelines? Thank you!

@@ -59,4 +59,9 @@ public void ignoreConfig(String field, Object value) {
logInfo("009", "Ignoring request configuration option with name '{}' and value '{}'", field, value);
}

public ConnectorRequestException unableToExecuteRequest(int statusCode , String connectorResponse) {
return new ConnectorRequestException(exceptionMessage("010", "Unable to execute HTTP request with Status Code : "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧 I'd rename this to httpRequestError or something similar and the message could also say something along HTTP request failed with status code: 500...
🔧 Let's also use the message template with parameters instead of string concatenation, like: "HTTP request failed with Status Code: {} , Response: {}", statusCode, connectorResponse)

throw LOG.unableToExecuteRequest(e);
}

R invocationResult = createResponse((CloseableHttpResponse) invocation.proceed());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧 Let's restructure this because this way the http error exception is caught and rethrown as unableToExecuteRequest: Move the new logic out from the try catch so it's not caught:

R invocationResult;
try {
  invocationResult = createResponse((CloseableHttpResponse) invocation.proceed());
} catch (Exception e) {
  throw LOG.unableToExecuteRequest(e);
}

handleErrorResponse(request, invocationResult);
return invocationResult;

Comment on lines 92 to 95
Optional<Object> handleHttpError = Optional.ofNullable(configOptions.get("throw-http-error"));

if (handleHttpError.isPresent() && handleHttpError.get().toString()
.equalsIgnoreCase("TRUE") && statusCode >= 400 && statusCode <= 599) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧 Maybe a bit more simple with orElse() and Boolean.parseBoolean:

Suggested change
Optional<Object> handleHttpError = Optional.ofNullable(configOptions.get("throw-http-error"));
if (handleHttpError.isPresent() && handleHttpError.get().toString()
.equalsIgnoreCase("TRUE") && statusCode >= 400 && statusCode <= 599) {
Object handleHttpError = Optional.ofNullable(configOptions.get("throw-http-error")).orElse("FALSE");
if (Boolean.parseBoolean(handleHttpError.toString()) && statusCode >= 400 && statusCode <= 599) {

@danielkelemen danielkelemen changed the title Feature/git issue 4241 http connector error handling enhancement feat(connect): add http connector response error handling Jun 27, 2024
Comment on lines 134 to 137
connector.createRequest().configOption("throw-http-error", "TRUE")
.url("http://camunda.com").get()
.execute();
} catch (ConnectorRequestException e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧 Let's add a fail in these tests so we notice if the logic is skipped for some reason. Otherwise, the test would still succeed.

Suggested change
connector.createRequest().configOption("throw-http-error", "TRUE")
.url("http://camunda.com").get()
.execute();
} catch (ConnectorRequestException e) {
connector.createRequest().configOption("throw-http-error", "TRUE")
.url("http://camunda.com").get()
.execute();
Assertions.fail("Should have thrown an exception");
} catch (ConnectorRequestException e) {

// then
assertThat(response.getStatusCode()).isEqualTo(200);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧 And please also add one more test case where throw-http-error is false and statusCode is an error (400-500). Thank you!

…rror handling enhancement for 4XX and 5XX errors

Contribution towards Camunda HTTP Connector enhancement for 4XX and 5XX errors -GIT Issue 4241

Signed-off-by: Shenoy, Nandan <[email protected]>
…or handling enhancement for 4XX and 5XX errors

Contribution towards Camunda HTTP Connector enhancement for 4XX and 5XX errors -GIT Issue 4241

Signed-off-by: Shenoy, Nandan <[email protected]>
…andling enhancement for 4XX and 5XX errors

Contribution towards Camunda HTTP Connector enhancement for 4XX and 5XX errors -GIT Issue 4241

Signed-off-by: Shenoy, Nandan <[email protected]>
…rror handling enhancement for 4XX and 5XX errors

Contribution towards Camunda HTTP Connector enhancement for 4XX and 5XX errors -GIT Issue 4241

Signed-off-by: Shenoy, Nandan <[email protected]>
@Nandanrshenoy
Copy link
Contributor Author

@danielkelemen ,
I have implemented all the review comments that were shared from your end.Kindly request you to review the same.

Thanks and Regards,
Nandan Shenoy

@danielkelemen
Copy link
Member

@Nandanrshenoy, Thank you! It looks really good. I'll run the CI in a local PR and then it'll be merged.

@Nandanrshenoy
Copy link
Contributor Author

@danielkelemen,Thanks for all your support.

@danielkelemen
Copy link
Member

Superseded with 42c77fc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants