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

#127 Improve Error Handling for Failed DefectDojo API Requests #128

Merged
merged 3 commits into from
Jul 27, 2024

Conversation

Weltraumschaf
Copy link
Member

Two Problems:

  1. We do not pass consequently the causing exception to our own custom exception.
  2. We do not catch all possible REST client runtime exceptions.

Fixed by consequent logging and passing ofthe origin exception as cause of our own excpetion. Also catching a more generic exception type totach all possible errors.

…quests

Two Problems:
1. We do not pass consequently the causing exception to our own custom
   exception.
2. We do not catch all possible REST client runtime exceptions.

Fixed by consequent logging and passing ofthe origin exception as
cause of our own excpetion. Also catching a more generic exception
type totach all possible errors.

Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
@Weltraumschaf Weltraumschaf self-assigned this Jul 12, 2024
@Weltraumschaf Weltraumschaf added the enhancement New feature or request label Jul 12, 2024

return response.getBody();
try {
ResponseEntity<T> response = restTemplate.exchange(
Copy link
Member

Choose a reason for hiding this comment

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

Did you intentionally only add this for the GET requests?
The error handling for the other http methods seems to be the same

Copy link
Member Author

Choose a reason for hiding this comment

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

🤔No. This means that any error handling is missing on non-GET bc I simply grepped HttpClientErrorException 😬


return response.getBody();
} catch (RestClientException e) {
log.error("Exception while getting data: {}", e.getMessage());
Copy link
Member

Choose a reason for hiding this comment

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

Whats in a message for a request client exception?
Is that enough for users to understand what request failed? Does it include the http method and url of the request?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a common pattern in Java that you simply log the exception message, if the exception is rethrown with the origin exception as cause because the full exception handling is done where the rethrown exception is catched. It's quite debatable if this log message is really necessary.

The conatenation will be done always, also if debug level is not
logged. So we should alwyas use parameterized log statements.

Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
…P Methods

In previous commits only GET requests were covered with proper
exception handling.

This adds rethrow of our own custom exception with the originating
error as cause, like already implemented for GET requests.

Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
@Weltraumschaf Weltraumschaf merged commit c2daf60 into secureCodeBox:main Jul 27, 2024
2 checks passed
@Weltraumschaf Weltraumschaf deleted the issue_127 branch July 27, 2024 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants