json - groovy: how to catch exceptions on AsyncHttpBuilder -


I am trying to create an async call in a domain. The following code works fine if I specify a valid address with the json response, but when the address is not valid, I want to capture any possible exceptions.

How can I catch exceptions back? / p>

A quote from StackTrace here:

Message: Invalid JSON string

...

http.AsyncHTTPBuilder - Exception throw From the given response reporter: groovyx.net.http.HTTPBuilder$RequestConfigDelegate@420db81e

Code here:

  def http = new asyncHTTPBuilder (poolSize: 1, contentType: ContentType.JSON) Def futureResult futureResult = http.request ("http://www.notexistingdomainxyzwq.com/", Method.GET, ContentType.JSON) {response.success = {resp, json -> Log.info ("success")} response.failure = {resp, json -> Log.info ("ERROR")}} log.info ("call start"); try {while (! futureResult.done) {log.info ('waiting ...') log.info ("done: $ {futureResult.done}") Thread.Sleep (1000)}} hold (east) { Log .error ("excellence $ {prior}")} log.info ("full call")    

If you ask to block futureResult.get () and wait for the result, it will throw the exception that you can hold: < pre> try {def result = futureResult.get () "login.info" ("dan: $ result")} hold (former) {log.error ("excel $ {east}")} < / Pre>

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -