Using RoboSpice is there a way to get the HTTP Error Code out of an exception?

前端 未结 5 821
失恋的感觉
失恋的感觉 2021-01-31 11:29

I am writing an application that uses RoboSpice. In the request listener onRequestFailure( SpiceException arg0 ) is there a way to know for sure that the error was a result of a

5条回答
  •  鱼传尺愫
    2021-01-31 12:19

    I am using the google http client with RoboSpice and has the same issue but was easy to solve with request.setThrowExceptionOnExecuteError(false); and checking the response code on the resulting HttpResponse object

    EDIT: the code snippit as requested

    HttpRequest request = getHttpRequestFactory().buildPostRequest(new GenericUrl(URL), content);
    request.setThrowExceptionOnExecuteError(false);
    HttpResponse response = request.execute();
    
    switch(response.getStatusCode())
        {
            case HttpStatusCodes.STATUS_CODE_UNAUTHORIZED:
                return new MyBaseResponse(responseBody);
            default:
                throw new RuntimeException("not implemented yet");
        }
    

提交回复
热议问题