-
Notifications
You must be signed in to change notification settings - Fork 12
#127 Improve Error Handling for Failed DefectDojo API Requests #128
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
import com.fasterxml.jackson.databind.cfg.CoercionInputShape; | ||
import io.securecodebox.persistence.defectdojo.config.Config; | ||
import io.securecodebox.persistence.defectdojo.exception.LoopException; | ||
import io.securecodebox.persistence.defectdojo.exception.PersistenceException; | ||
import io.securecodebox.persistence.defectdojo.http.Foo; | ||
import io.securecodebox.persistence.defectdojo.http.ProxyConfigFactory; | ||
import io.securecodebox.persistence.defectdojo.model.Engagement; | ||
|
@@ -29,6 +30,7 @@ | |
import org.springframework.http.converter.StringHttpMessageConverter; | ||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; | ||
import org.springframework.util.LinkedMultiValueMap; | ||
import org.springframework.web.client.RestClientException; | ||
import org.springframework.web.client.RestTemplate; | ||
import org.springframework.web.util.UriComponentsBuilder; | ||
|
||
|
@@ -73,14 +75,19 @@ public final T get(long id) { | |
|
||
final var url = this.config.getUrl() + API_PREFIX + this.getUrlPath() + "/" + id; | ||
log.debug("Requesting URL: {}", url); | ||
ResponseEntity<T> response = restTemplate.exchange( | ||
url, | ||
HttpMethod.GET, | ||
payload, | ||
getModelClass() | ||
); | ||
|
||
return response.getBody(); | ||
try { | ||
ResponseEntity<T> response = restTemplate.exchange( | ||
url, | ||
HttpMethod.GET, | ||
payload, | ||
getModelClass() | ||
); | ||
|
||
return response.getBody(); | ||
} catch (RestClientException e) { | ||
log.error("Exception while getting data: {}", e.getMessage()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whats in a message for a request client exception? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
throw new PersistenceException("Failed to get data.", e); | ||
} | ||
} | ||
|
||
@Override | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
😬