@Test public void quotaExceededError() { mInterceptor.setFile("4sq-429.json") .setCode(429); assertError(mFoursquareClient.getMosqueList(3.1390006, 101.677240, 20), QuotaExceededException.class); }
@Override public Observable<List<Mosque>> getMosqueList(double lat, double lng, int radius) { String latLng = String.format("%s,%s", lat, lng); return mApi.searchVenue(getQuery(), getIntent(), radius, 25, "4bf58dd8d48988d138941735", latLng) .map(new Func1<FoursquareResponse, List<Mosque>>() { @Override public List<Mosque> call(FoursquareResponse r) { return r.getMosques(); } }) .onErrorResumeNext(new Func1<Throwable, Observable<? extends List<Mosque>>>() { @Override public Observable<? extends List<Mosque>> call(Throwable e) { if (e instanceof HttpException) { HttpException he = (HttpException) e; Response<?> r = he.response(); if (r != null) { Converter<ResponseBody, FoursquareResponse> converter = mRetrofit .responseBodyConverter(FoursquareResponse.class, new Annotation[0]); FoursquareResponse body; try { body = converter.convert(r.errorBody()); if (body != null && "quota_exceeded".equals(body.meta.errorType)) { return Observable.error(new QuotaExceededException()); } } catch (IOException ie) { } } } return Observable.error(e); } }); }
RetrofitFoursquareClient implements FoursquareClient { @Override public Observable<List<Mosque>> getMosqueList(double lat, double lng, int radius) { String latLng = String.format("%s,%s", lat, lng); return mApi.searchVenue(getQuery(), getIntent(), radius, 25, "4bf58dd8d48988d138941735", latLng) .map(new Func1<FoursquareResponse, List<Mosque>>() { @Override public List<Mosque> call(FoursquareResponse r) { return r.getMosques(); } }) .onErrorResumeNext(new Func1<Throwable, Observable<? extends List<Mosque>>>() { @Override public Observable<? extends List<Mosque>> call(Throwable e) { if (e instanceof HttpException) { HttpException he = (HttpException) e; Response<?> r = he.response(); if (r != null) { Converter<ResponseBody, FoursquareResponse> converter = mRetrofit .responseBodyConverter(FoursquareResponse.class, new Annotation[0]); FoursquareResponse body; try { body = converter.convert(r.errorBody()); if (body != null && "quota_exceeded".equals(body.meta.errorType)) { return Observable.error(new QuotaExceededException()); } } catch (IOException ie) { } } } return Observable.error(e); } }); } }
RetrofitFoursquareClient implements FoursquareClient { @Override public Observable<List<Mosque>> getMosqueList(double lat, double lng, int radius) { String latLng = String.format("%s,%s", lat, lng); return mApi.searchVenue(getQuery(), getIntent(), radius, 25, "4bf58dd8d48988d138941735", latLng) .map(new Func1<FoursquareResponse, List<Mosque>>() { @Override public List<Mosque> call(FoursquareResponse r) { return r.getMosques(); } }) .onErrorResumeNext(new Func1<Throwable, Observable<? extends List<Mosque>>>() { @Override public Observable<? extends List<Mosque>> call(Throwable e) { if (e instanceof HttpException) { HttpException he = (HttpException) e; Response<?> r = he.response(); if (r != null) { Converter<ResponseBody, FoursquareResponse> converter = mRetrofit .responseBodyConverter(FoursquareResponse.class, new Annotation[0]); FoursquareResponse body; try { body = converter.convert(r.errorBody()); if (body != null && "quota_exceeded".equals(body.meta.errorType)) { return Observable.error(new QuotaExceededException()); } } catch (IOException ie) { } } } return Observable.error(e); } }); } RetrofitFoursquareClient(OkHttpClient client); }
RetrofitFoursquareClient implements FoursquareClient { @Override public Observable<List<Mosque>> getMosqueList(double lat, double lng, int radius) { String latLng = String.format("%s,%s", lat, lng); return mApi.searchVenue(getQuery(), getIntent(), radius, 25, "4bf58dd8d48988d138941735", latLng) .map(new Func1<FoursquareResponse, List<Mosque>>() { @Override public List<Mosque> call(FoursquareResponse r) { return r.getMosques(); } }) .onErrorResumeNext(new Func1<Throwable, Observable<? extends List<Mosque>>>() { @Override public Observable<? extends List<Mosque>> call(Throwable e) { if (e instanceof HttpException) { HttpException he = (HttpException) e; Response<?> r = he.response(); if (r != null) { Converter<ResponseBody, FoursquareResponse> converter = mRetrofit .responseBodyConverter(FoursquareResponse.class, new Annotation[0]); FoursquareResponse body; try { body = converter.convert(r.errorBody()); if (body != null && "quota_exceeded".equals(body.meta.errorType)) { return Observable.error(new QuotaExceededException()); } } catch (IOException ie) { } } } return Observable.error(e); } }); } RetrofitFoursquareClient(OkHttpClient client); @Override Observable<List<Mosque>> getMosqueList(double lat, double lng, int radius); @Override String getQuery(); @Override String getIntent(); }
RetrofitFoursquareClient implements FoursquareClient { @Override public Observable<List<Mosque>> getMosqueList(double lat, double lng, int radius) { String latLng = String.format("%s,%s", lat, lng); return mApi.searchVenue(getQuery(), getIntent(), radius, 25, "4bf58dd8d48988d138941735", latLng) .map(new Func1<FoursquareResponse, List<Mosque>>() { @Override public List<Mosque> call(FoursquareResponse r) { return r.getMosques(); } }) .onErrorResumeNext(new Func1<Throwable, Observable<? extends List<Mosque>>>() { @Override public Observable<? extends List<Mosque>> call(Throwable e) { if (e instanceof HttpException) { HttpException he = (HttpException) e; Response<?> r = he.response(); if (r != null) { Converter<ResponseBody, FoursquareResponse> converter = mRetrofit .responseBodyConverter(FoursquareResponse.class, new Annotation[0]); FoursquareResponse body; try { body = converter.convert(r.errorBody()); if (body != null && "quota_exceeded".equals(body.meta.errorType)) { return Observable.error(new QuotaExceededException()); } } catch (IOException ie) { } } } return Observable.error(e); } }); } RetrofitFoursquareClient(OkHttpClient client); @Override Observable<List<Mosque>> getMosqueList(double lat, double lng, int radius); @Override String getQuery(); @Override String getIntent();  }