<commit_before>package amatkivskiy.gitter.rx.sdk.api;

import amatkivskiy.gitter.rx.sdk.model.error.GitterApiErrorResponse;
import amatkivskiy.gitter.rx.sdk.model.error.GitterApiException;
import retrofit.ErrorHandler;
import retrofit.RestAdapter;
import retrofit.RestAdapter.Builder;
import retrofit.RestAdapter.Log;
import retrofit.RestAdapter.LogLevel;
import retrofit.RetrofitError;
import retrofit.client.Client;
import retrofit.client.Client.Provider;

public abstract class BaseApiClient {
  private final ErrorHandler defaultErrorHandler = new ErrorHandler() {
    @Override
    public Throwable handleError(RetrofitError cause) {
      Throwable returnThrowable = cause;
      if (cause.getKind() == RetrofitError.Kind.HTTP) {
        if (cause.getResponse() != null) {
          GitterApiErrorResponse errorResponse = (GitterApiErrorResponse) cause.getBodyAs(GitterApiErrorResponse.class);

          returnThrowable = new GitterApiException(errorResponse);
          returnThrowable.setStackTrace(cause.getStackTrace());
        }
      }

      return returnThrowable;
    }
  };
  
  protected RestAdapter.Builder adapterBuilder;

  public BaseApiClient() {
    adapterBuilder = new Builder().setEndpoint(getFullEndpointUrl());
    adapterBuilder.setErrorHandler(getDefaultErrorHandler());
  }

  protected abstract String getEndpointUrl();

  protected abstract String getEndpointVersion();

  protected <ApiClass> ApiClass createApi(RestAdapter adapter, Class<ApiClass> service) {
    return adapter.create(service);
  }

  protected ErrorHandler getDefaultErrorHandler() {
    return defaultErrorHandler;
  }

  protected String getFullEndpointUrl() {
    if (getEndpointVersion() != null && !getEndpointVersion().isEmpty()) {
      return getEndpointUrl() + "/" + getEndpointVersion() + "/";
    }
    return getEndpointUrl();
  }

  public void setClient(Client client) {
    adapterBuilder.setClient(client);
  }

  public void setClient(Provider clientProvider) {
    adapterBuilder.setClient(clientProvider);
  }

  public void setLog(Log log) {
    adapterBuilder.setLog(log);
  }

  public void setLogLevel(LogLevel logLevel) {
    adapterBuilder.setLogLevel(logLevel);
  }
}
<commit_msg>Fixed null GitterApiErrorResponse in GitterApiException.<commit_after>package amatkivskiy.gitter.rx.sdk.api;

import amatkivskiy.gitter.rx.sdk.model.error.GitterApiErrorResponse;
import amatkivskiy.gitter.rx.sdk.model.error.GitterApiException;
import retrofit.ErrorHandler;
import retrofit.RestAdapter;
import retrofit.RestAdapter.Builder;
import retrofit.RestAdapter.Log;
import retrofit.RestAdapter.LogLevel;
import retrofit.RetrofitError;
import retrofit.client.Client;
import retrofit.client.Client.Provider;

public abstract class BaseApiClient {
  private final ErrorHandler defaultErrorHandler = new ErrorHandler() {
    @Override
    public Throwable handleError(RetrofitError cause) {
      Throwable returnThrowable = cause;
      if (cause.getKind() == RetrofitError.Kind.HTTP) {
        if (cause.getResponse() != null) {
          GitterApiErrorResponse errorResponse = (GitterApiErrorResponse) cause.getBodyAs(GitterApiErrorResponse.class);

          if (errorResponse != null) {
            returnThrowable = new GitterApiException(errorResponse);
            returnThrowable.setStackTrace(cause.getStackTrace());
          }
        }
      }

      return returnThrowable;
    }
  };

  protected RestAdapter.Builder adapterBuilder;

  public BaseApiClient() {
    adapterBuilder = new Builder().setEndpoint(getFullEndpointUrl());
    adapterBuilder.setErrorHandler(getDefaultErrorHandler());
  }

  protected abstract String getEndpointUrl();

  protected abstract String getEndpointVersion();

  protected <ApiClass> ApiClass createApi(RestAdapter adapter, Class<ApiClass> service) {
    return adapter.create(service);
  }

  protected ErrorHandler getDefaultErrorHandler() {
    return defaultErrorHandler;
  }

  protected String getFullEndpointUrl() {
    if (getEndpointVersion() != null && !getEndpointVersion().isEmpty()) {
      return getEndpointUrl() + "/" + getEndpointVersion() + "/";
    }
    return getEndpointUrl();
  }

  public void setClient(Client client) {
    adapterBuilder.setClient(client);
  }

  public void setClient(Provider clientProvider) {
    adapterBuilder.setClient(clientProvider);
  }

  public void setLog(Log log) {
    adapterBuilder.setLog(log);
  }

  public void setLogLevel(LogLevel logLevel) {
    adapterBuilder.setLogLevel(logLevel);
  }
}

{'fraction_non_alphanumeric': 0.09583886675520141, 'fraction_numerical': 0.0, 'mean_word_length': 4.405502392344498, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5630007', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1250, 'n_words': 245}