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

add error information for when sonatype fails #32

Merged
merged 2 commits into from
Mar 19, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.codearte.gradle.nexus.infra

import org.apache.http.client.HttpResponseException;

import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import groovyx.net.http.ContentType
Expand Down Expand Up @@ -51,8 +53,18 @@ class SimplifiedHttpJsonRestClient {
Map params = createAndInitializeCallParametersMap()
params.body = content
log.debug("POST request content: $content")
//TODO: Add better error handling (e.g. display error message received from server, not only 500 + not fail on 404 in 'text/html')
HttpResponseDecorator response = (HttpResponseDecorator)restClient.post(params)
log.warn("POST response data: ${response.data}")
try {
//TODO: Add better error handling (e.g. display error message received from server, not only 500 + not fail on 404 in 'text/html')
Copy link
Member

Choose a reason for hiding this comment

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

This comment is no longer valid after your changes :).

HttpResponseDecorator response = (HttpResponseDecorator)restClient.post(params)
log.warn("POST response data: ${response.data}")
} catch(groovyx.net.http.HttpResponseException e) {
Copy link
Member

Choose a reason for hiding this comment

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

Missing space after catch

//Apache' HttpResponseException ONLY puts the 2nd param in the e.getMessage which will be printed so
//put all information there (status code, error str, body of response in case they put more error information there)

HttpResponseDecorator resp = e.getResponse();
String message = "${resp.statusLine.statusCode}:${resp.statusLine.reasonPhrase} body=${resp.data}"
Copy link
Member

Choose a reason for hiding this comment

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

(two spaces) before body - one would be enough.

log.error("POST response failed. ${message}")
throw new HttpResponseException(e.getStatusCode(), message)
Copy link
Member

Choose a reason for hiding this comment

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

We lose original stacktrace. Please include e as a cause.

}
Copy link
Member

Choose a reason for hiding this comment

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

Please reformat this code fragment in general. It seems your are using tabs instead of spaces.

Copy link
Member

Choose a reason for hiding this comment

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

I created #33 to better handle that.

}
}