<commit_before>module GdsApi
  class BaseError < StandardError
  end

  class EndpointNotFound < BaseError
  end

  class TimedOutException < BaseError
  end

  class TooManyRedirects < BaseError
  end

  class HTTPErrorResponse < BaseError
    attr_accessor :code, :error_details

    def initialize(code, message = nil, error_details = nil, request_body = nil)
      super(message)
      @code = code
      @error_details = error_details
      @request_body = request_body
    end
  end

  class HTTPClientError < HTTPErrorResponse
  end

  class HTTPServerError < HTTPErrorResponse
  end

  class HTTPNotFound < HTTPClientError
  end

  class HTTPGone < HTTPClientError
  end

  class HTTPUnauthorized < HTTPClientError
  end

  class HTTPForbidden < HTTPClientError
  end

  class HTTPConflict < HTTPClientError
  end

  class NoBearerToken < BaseError; end

  module ExceptionHandling
    def ignoring(exception_or_exceptions, &block)
      yield
    rescue *exception_or_exceptions
      # Discard the exception
    end

    def ignoring_missing(&block)
      ignoring([HTTPNotFound, HTTPGone], &block)
    end

    def build_specific_http_error(error, url, details = nil, request_body = nil)
      message = "URL: #{url}\nResponse body:\n#{error.http_body}\n\nRequest body:\n#{request_body}"
      code = error.http_code
      error_class_for_code(code).new(code, message, details)
    end

    def error_class_for_code(code)
      case code
      when 401
        GdsApi::HTTPUnauthorized
      when 403
        GdsApi::HTTPForbidden
      when 404
        GdsApi::HTTPNotFound
      when 409
        GdsApi::HTTPConflict
      when 410
        GdsApi::HTTPGone
      when (400..499)
        GdsApi::HTTPClientError
      when (500..599)
        GdsApi::HTTPServerError
      else
        GdsApi::HTTPErrorResponse
      end
    end
  end
end
<commit_msg>Add exception for 422 errors<commit_after>module GdsApi
  class BaseError < StandardError
  end

  class EndpointNotFound < BaseError
  end

  class TimedOutException < BaseError
  end

  class TooManyRedirects < BaseError
  end

  class HTTPErrorResponse < BaseError
    attr_accessor :code, :error_details

    def initialize(code, message = nil, error_details = nil, request_body = nil)
      super(message)
      @code = code
      @error_details = error_details
      @request_body = request_body
    end
  end

  class HTTPClientError < HTTPErrorResponse
  end

  class HTTPServerError < HTTPErrorResponse
  end

  class HTTPNotFound < HTTPClientError
  end

  class HTTPGone < HTTPClientError
  end

  class HTTPUnauthorized < HTTPClientError
  end

  class HTTPForbidden < HTTPClientError
  end

  class HTTPConflict < HTTPClientError
  end

  class HTTPUnprocessableEntity < HTTPClientError
  end

  class NoBearerToken < BaseError; end

  module ExceptionHandling
    def ignoring(exception_or_exceptions, &block)
      yield
    rescue *exception_or_exceptions
      # Discard the exception
    end

    def ignoring_missing(&block)
      ignoring([HTTPNotFound, HTTPGone], &block)
    end

    def build_specific_http_error(error, url, details = nil, request_body = nil)
      message = "URL: #{url}\nResponse body:\n#{error.http_body}\n\nRequest body:\n#{request_body}"
      code = error.http_code
      error_class_for_code(code).new(code, message, details)
    end

    def error_class_for_code(code)
      case code
      when 401
        GdsApi::HTTPUnauthorized
      when 403
        GdsApi::HTTPForbidden
      when 404
        GdsApi::HTTPNotFound
      when 409
        GdsApi::HTTPConflict
      when 410
        GdsApi::HTTPGone
      when 422
        GdsApi::HTTPUnprocessableEntity
      when (400..499)
        GdsApi::HTTPClientError
      when (500..599)
        GdsApi::HTTPServerError
      else
        GdsApi::HTTPErrorResponse
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.06047235920062289, 'fraction_numerical': 0.015572281339216195, 'mean_word_length': 2.892929292929293, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 3, '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': '484181', 'n_tokens_mistral': 1216, 'n_tokens_neox': 1160, 'n_words': 291}