Crest ErrorHandler获取响应数据

ste*_*fan 0 java rest android

我们正在开发一个Android应用程序,我们想要使用crest lib.我们正在使用的Web服务在某些情况下400返回错误请求以及json格式的其他响应数据.我们有成功的响应处理程序和坏请求的错误处理程序.是否可以在错误处理程序中获取返回的数据?

错误处理程序

public class RestErrorHandler implements ErrorHandler{

@Override
public <T> T handle(Request request, Exception e) throws Exception {

    // here we need to check the code returned from the 
    // web service in case of a bad request
    return null;
}

}
Run Code Online (Sandbox Code Playgroud)

坏请求看起来像这样:

HTTP/1.1 400 Bad Request
Content-Length: 59
Date: Wed, 08 Feb 2012 15:01:23 GMT
Server: Apache
Set-Cookie: session=A…...
Status: 400
Vary: Accept-Encoding
Connection: close
Content-Type: application/json
{"status":false,"code":"403","message":"wrong credentials"}
Run Code Online (Sandbox Code Playgroud)

rwo*_*iak 6

很抱歉找到这么老的问题,但我也偶然发现了这个问题,其他人可能会觉得答案很有帮助.

如果异常与http相关,则可以将org.codegist.crest.io.RequestException其转换为具有getResponse()方法的异常.

更多信息:https://github.com/codegist/crest/issues/9