Robospice 面临错误但调用了 onRequestSuccess

Robospice faces Error but onRequestSuccess is called

我正在向服务器发送请求,但是当我遇到

Client org.springframework.web.client.HttpClientErrorException: 400 BAD REQUEST

调用 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);
    }
}

只要您正在捕获 loadDataFromNetwork() 中的异常并且不重新抛出它们,RoboSpice 就认为没有发生异常。传播错误的唯一方法是从你的 loadDataFromNetwork() 中抛出它,然后你将通过 onRequestFailure.

被回调