Robospice面临Error但调用onRequestSuccess

时间:2015-05-25 06:34:38

标签: java android robospice

我正在POST服务器请求,但是当我面对

  

客户端org.springframework.web.client.HttpClientErrorException:400   不好请求

调用onRequestSuccess而不是onRequestFailure

public String loadDataFromNetwork()  {

   String url =  "myurl";

    HttpHeaders header = new HttpHeaders();
    header.setContentType(new MediaType("application", "json"));

    try {
        JSONObject jsonObject =  new JSONObject();
        jsonObject.put(constants.TAG_ORDER_ID, bOrderID);

        RestTemplate restTemplate = new RestTemplate(true);
        restTemplate.getMessageConverters().add(new GsonHttpMessageConverter());

        HttpEntity<?> httpEntity = new HttpEntity<Object>( jsonObject.toString() , header);


        ResponseEntity r = restTemplate.exchange(url, HttpMethod.POST, httpEntity, getResultType());

        return r.toString();
    }
    catch (HttpClientErrorException e){
        return String.valueOf(e);
    }
    catch (JSONException e){
        return String.valueOf(e);
    }
}

1 个答案:

答案 0 :(得分:0)

只要您正在捕捉FFI:Def-call-in内的异常而不是重新抛出它们,RoboSpice认为没有发生任何异常。传播错误的唯一方法是从loadDataFromNetwork()中抛出错误,然后通过loadDataFromNetwork()回复。