OkHttpExceptionUtil.java
760 Bytes
package com.share.mvpsdk.utils;
import android.support.annotation.NonNull;
import org.json.JSONObject;
import okhttp3.ResponseBody;
import retrofit2.HttpException;
import retrofit2.Response;
/**
* Created by 10501 on 2017/7/18.
*/
public class OkHttpExceptionUtil {
public static void handOkHttpException(@NonNull HttpException e){
Response response = e.response();
if (response==null)return;
ResponseBody responseBody = response.errorBody();
if (responseBody==null)return;
try {
JSONObject json = new JSONObject(responseBody.string());
ToastUtils.showToast(json.optString("message")+"json="+json);
} catch (Exception e1) {
e1.printStackTrace();
}
}
}