use of retrofit.ErrorHandler in project steps by linroid.
the class WeatherApp method initWeatherService.
private void initWeatherService() {
RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(Config.ENDPOINT).setClient(new OkClient(new OkHttpClient())).setLogLevel(RestAdapter.LogLevel.BASIC).setErrorHandler(new ErrorHandler() {
@Override
public Throwable handleError(RetrofitError retrofitError) {
Timber.e(retrofitError, "访问 %s 出错", retrofitError.getUrl());
return retrofitError;
}
}).setRequestInterceptor(new RequestInterceptor() {
@Override
public void intercept(RequestFacade requestFacade) {
requestFacade.addQueryParam("ak", Config.BAIDU_AK);
requestFacade.addEncodedQueryParam("mcode", Config.M_CODE);
requestFacade.addQueryParam("output", "json");
}
}).build();
weatherService = restAdapter.create(WeatherService.class);
}
Aggregations