From 8d7a6a7cf6ecab627f7d04f679fb738283a2be4e Mon Sep 17 00:00:00 2001 From: Michael Cameron Date: Thu, 12 Jul 2012 13:47:39 -0500 Subject: [PATCH] Preserve response data on error. RESTClient still has response data for HTTP >= 400 status --- .../functionaltest/client/APIClient.groovy | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/groovy/com/grailsrocks/functionaltest/client/APIClient.groovy b/src/groovy/com/grailsrocks/functionaltest/client/APIClient.groovy index f7d3aff..de8e332 100644 --- a/src/groovy/com/grailsrocks/functionaltest/client/APIClient.groovy +++ b/src/groovy/com/grailsrocks/functionaltest/client/APIClient.groovy @@ -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,