我在用着retrofit
调用网络服务和改造会引发失败,来自“Throwable”的消息给了我
java.lang.IllegalStateException:预期为 BEGIN_OBJECT,但在第 1 行第 1 列路径 $ 处为 STRING
我假设这是因为 .Net Web 服务抛出错误并且不返回 JSON。但为了证明这一点,我需要能够看到原始响应onFailure
。无论如何我可以做到这一点吗?
这是我正在使用的代码
public void userLoginRequestEvent(final AuthenticateUserEvent event) {
Call call = sApi.login(event.getUsername(), event.getPassword(), OS_TYPE, DeviceInfoUtils.getDeviceName());
call.enqueue(new Callback<LoggedInUser>() {
@Override
public void onResponse(Response<LoggedInUser> response, Retrofit retrofit) {
// response.isSuccess() is true if the response code is 2xx
if (response.isSuccess()) {
LoggedInUser user = response.body();
AppBus.getInstance()
.post(new UserIsAuthenticatedEvent(user, event.getUsername(),
event.getPassword()));
} else {
int statusCode = response.code();
// handle request errors yourself
}
}
@Override
public void onFailure(Throwable t) {
// handle execution failures like no internet connectivity
Log.d("ERROR", t.getMessage());
}
});
您可以使用存在于okhttp-logging-拦截器 https://github.com/square/okhttp/tree/master/okhttp-logging-interceptor.
一个很好的例子可以在使用 Retrofit 2 进行日志记录 https://stackoverflow.com/questions/32514410/logging-with-retrofit-2以及。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)