Search in sources :

Example 1 with ErrorHandler

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);
}
Also used : ErrorHandler(retrofit.ErrorHandler) OkHttpClient(com.squareup.okhttp.OkHttpClient) OkClient(retrofit.client.OkClient) WeatherService(com.linroid.weather.data.WeatherService) RequestInterceptor(retrofit.RequestInterceptor) RestAdapter(retrofit.RestAdapter) RetrofitError(retrofit.RetrofitError)

Aggregations

WeatherService (com.linroid.weather.data.WeatherService)1 OkHttpClient (com.squareup.okhttp.OkHttpClient)1 ErrorHandler (retrofit.ErrorHandler)1 RequestInterceptor (retrofit.RequestInterceptor)1 RestAdapter (retrofit.RestAdapter)1 RetrofitError (retrofit.RetrofitError)1 OkClient (retrofit.client.OkClient)1