我使用retrofit
調用Web服務和改造拋出一個失敗,從「Throwable`的消息是給我改造2.0 onFailure處 - 原始響應
java.lang.IllegalStateException:預期BEGIN_OBJECT但STRING在1行1列路徑$
我假設這是因爲.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());
}
});
嘗試使用方法記錄請求/響應http://stackoverflow.com/questions/32514410/logging-with-retrofit-2 – keno
請提供完整的stacktrace列表以及api界面列表。你可以通過在'onFailure(Throwable t)'方法中添加't.printStackTrace()'來打印完整的堆棧跟蹤。 沒有注意到這個問題有多大。它還沒解決嗎? :) –
@КлаусШварц它是由第一條評論解決的,但沒有回覆發佈,我可以接受 – Flexicoder