From b583e0d64a183b4e55caebddd8852729d9565a07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Zaj=C4=85czkowski?= Date: Mon, 7 Dec 2015 23:41:49 +0100 Subject: [PATCH] Enhance error handling with URLConnection Response content can be read in case of error --- src/test/groovy/org/kar/http/GroovyHttpClientTest.groovy | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/test/groovy/org/kar/http/GroovyHttpClientTest.groovy b/src/test/groovy/org/kar/http/GroovyHttpClientTest.groovy index 2c3e80b..f4175f5 100644 --- a/src/test/groovy/org/kar/http/GroovyHttpClientTest.groovy +++ b/src/test/groovy/org/kar/http/GroovyHttpClientTest.groovy @@ -116,15 +116,11 @@ class GroovyHttpClientTest extends Specification { def "from a String to URLConnection with error handling"() { when: - String html final HttpURLConnection connection = makeURL('notThere.groovy').toURL().openConnection() - connection.inputStream.withReader { Reader reader -> - html = reader.text - } then: connection.responseCode == HttpServletResponse.SC_NOT_FOUND - def e = thrown(FileNotFoundException) + connection.errorStream.text.contains("Error 404 NOT_FOUND") } // START SNIPPET groovy-http::Listing5.groovy def "POST from a URLConnection"() {