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

Preserve response data on error. RESTClient still has response data for HTTP >= 400 status #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
26 changes: 26 additions & 0 deletions src/groovy/com/grailsrocks/functionaltest/client/APIClient.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,32 @@ class APIClient implements Client {
statusCode: responseStatus)
} catch (HttpResponseException e) {
response = e.response

if (response.data != null) {

// @todo need to copy the response data first, then mutate it to string also
// as RESTClient only lets you read the response once.

switch (response.contentType) {
case ~'application/json.*':
case ~'text/.*':
responseString = response.data.text
break;
default:
println "yresp is: ${response.data.getClass()}"
byte[] bytes = new byte[100]
response.data.read(bytes)
responseString = "Binary file:\r\n" + new String(bytes, 'utf-8')
def n = response.data.available()
if (n) {
responseString += "\r\n and $n more bytes"
}
break;
}
} else {
responseString = ''
}

event = new ContentChangedEvent(
client: this,
url: this.url,
Expand Down