美文网首页
Retrofit2 + Rxjava处理HttpExceptio

Retrofit2 + Rxjava处理HttpExceptio

作者: 郭某人1 | 来源:发表于2018-04-18 17:42 被阅读45次

服务器返回的错误信息为: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处理HttpExceptio

      本文链接:https://www.haomeiwen.com/subject/usjekftx.html