[rest-gradle-plugin] 44/83: Add better logging and exception handling.

Alastair McKinstry mckinstry at moszumanska.debian.org
Wed Oct 25 15:59:06 UTC 2017


This is an automated email from the git hooks/post-receive script.

mckinstry pushed a commit to branch debian/master
in repository rest-gradle-plugin.

commit b25c98aee82abcc059cb09fbb24bff495ba2d4ae
Author: Doug Borg <dougborg at dougborg.org>
Date:   Wed Feb 18 13:52:04 2015 -0700

    Add better logging and exception handling.
    
    I was having trouble setting up my task and needed better logging and exception handling in order to understand what was happening with my HttpRequests. Hopefully others will find these changes useful as well.
---
 src/main/groovy/org/_10ne/gradle/rest/RestTask.groovy | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/main/groovy/org/_10ne/gradle/rest/RestTask.groovy b/src/main/groovy/org/_10ne/gradle/rest/RestTask.groovy
index d22d4c3..3230e24 100644
--- a/src/main/groovy/org/_10ne/gradle/rest/RestTask.groovy
+++ b/src/main/groovy/org/_10ne/gradle/rest/RestTask.groovy
@@ -25,6 +25,8 @@ import org.gradle.api.InvalidUserDataException
 import org.gradle.api.tasks.Input
 import org.gradle.api.tasks.Optional
 import org.gradle.api.tasks.TaskAction
+import org.gradle.api.GradleException
+
 /**
  * @author Noam Y. Tenne
  */
@@ -60,7 +62,7 @@ class RestTask extends DefaultTask {
         String proxyHost = System.getProperty("${protocol}.proxyHost", '')
         int proxyPort = System.getProperty("${protocol}.proxyPort", '0') as int
         if (StringUtils.isNotBlank(proxyHost) && proxyPort > 0) {
-            println "Using ${protocol.toUpperCase()} proxy: $proxyHost:$proxyPort"
+            logger.info "Using ${protocol.toUpperCase()} proxy: $proxyHost:$proxyPort"
             client.setProxy(proxyHost, proxyPort, protocol)
         }
     }
@@ -97,8 +99,13 @@ class RestTask extends DefaultTask {
             params.requestContentType = requestContentType
         }
 
-        println "Executing a '$httpMethod' request to '$uri'"
+        logger.info "Executing a '$httpMethod' request to '$uri'"
 
-        serverResponse = client."${httpMethod.toLowerCase()}"(params)
+        try {
+            serverResponse = client."${httpMethod.toLowerCase()}"(params)
+            logger.info "Server Response:" + System.lineSeparator() + serverResponse.getData()
+        } catch(groovyx.net.http.HttpResponseException e) {
+            throw new GradleException(e.getResponse().getData().toString(), e)
+        }
     }
-}
\ No newline at end of file
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/rest-gradle-plugin.git



More information about the pkg-java-commits mailing list