Retrofit2 + Rxjava处理HttpException错误信息

服务器返回的错误信息为:Http400,解决办法:

    if (throwable instanceof HttpException) {
        try {
            ResponseBody body = ((HttpException) throwable).response().errorBody();
            Gson gson = new Gson();
            String res = body.string();
            BaseEntity entity = gson.fromJson(res, BaseEntity.class);
            ToastUtil.showToast(new String(entity.getMsg()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

你可能感兴趣的:(Retrofit2 + Rxjava处理HttpException错误信息)