package com.share.mvpsdk.utils; import android.support.annotation.NonNull; import android.util.Log; 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()); Log.d("77777",json.toString()); ToastUtils.showToast(json.optString("error")); } catch (Exception e1) { e1.printStackTrace(); } } }