2015-03-03 14 views

cevap

4

özel başarısız tepki işleyicisi ekleyin:: Aslında

 restClient = new RESTClient("http://${Server}") 
     restClient.handler.failure = { resp, data -> 
      resp.setData(data) 
      String headers = "" 
      resp.headers.each { 
       headers = headers+"${it.name} : ${it.value}\n" 
      } 
      throw new HttpResponseException(resp.getStatus(),"HTTP call failed. Status code: ${resp.getStatus()}\n${headers}\n"+ 
              "Response: "+(resp as HttpResponseDecorator).getData()) 
      return resp 
     } 
0

, çıkartabilirsiniz İşte

Ben

restClient = new RESTClient("http://${Server}") 
try { 
    HttpResponseDecorator resp = restClient.post(path,body,requestContentType)  
     as HttpResponseDecorator 
    return JSONObject.fromObject(resp.getData()).get("topKey",""); 
    } 
catch (HttpResponseException e) { 
      error(e.toString()) 
    } 

Ve sadece çıkış bu kullanıyorum kodudur atılan istisnadan tam yanıt. Örneğin yakalanan istisnanız e ise ve yanıt gövdesi JSON myCustomErrorCode adlı bir alan içermeli, e.statusCode'a ek olarak e.response.data.myCustomErrorCode'a bakarak değerini kontrol edebilirsiniz.

İlgili konular