class ErrorInterceptor implements Interceptor {

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();
        Response response = chain.proceed(request);

        if (response.code() >= 200 && response.code() <= 299) {
            return response;
        }
        ErrorFeed errorFeed = new Gson().fromJson(response.body().charStream(), ErrorFeed.class);

        if (errorFeed != null && errorFeed.errors != null && !errorFeed.errors.isEmpty()) {
            response.body().close();
            throw errorFeed.errors.get(0);
        }

        return response;
    }

}