<commit_before>require 'faraday'
require 'json'

module Envato
  module Connection
    def get(url)
      request :get, url
    end

    def ssl_opts
      { verify: true }
    end

    def api_host
      'https://api.envato.com'
    end

    private

    def request(method, url, options = {})
      request = Faraday.new(url: api_host, ssl: ssl_opts) do |c|
        c.adapter Faraday.default_adapter
        c.headers['User-Agent'] = "Envato SDK (#{Envato::VERSION})"
        c.authorization(:Bearer, @access_token)
        c.proxy(@proxy) if @proxy
      end

      case method
      when :get
        response = request.get(url)
      end

      case response.status.to_i
        when 403      then raise Envato::ForbiddenError, extract_forbidden_message(response)
        when 404      then raise Envato::NotFoundError
        when 405..499 then raise Envato::ClientError
        when 500..599 then raise Envato::ServerError, extract_server_error_message(response)
      end

      begin
        JSON.parse(response.body)
      rescue JSON::ParserError
        response.body
      end
    end

    def extract_forbidden_message(response)
      body = JSON.parse(response.body)
      body['error_description']
    end

    def extract_server_error_message(response)
      body = JSON.parse(response.body)
      body['message']
    end
  end
end
<commit_msg>Extract the error message from the 404 response<commit_after>require 'faraday'
require 'json'

module Envato
  module Connection
    def get(url)
      request :get, url
    end

    def ssl_opts
      { verify: true }
    end

    def api_host
      'https://api.envato.com'
    end

    private

    def request(method, url, options = {})
      request = Faraday.new(url: api_host, ssl: ssl_opts) do |c|
        c.adapter Faraday.default_adapter
        c.headers['User-Agent'] = "Envato SDK (#{Envato::VERSION})"
        c.authorization(:Bearer, @access_token)
        c.proxy(@proxy) if @proxy
      end

      case method
      when :get
        response = request.get(url)
      end

      case response.status.to_i
        when 403      then raise Envato::ForbiddenError, extract_forbidden_message(response)
        when 404      then raise Envato::NotFoundError, extract_not_found_message(response)
        when 405..499 then raise Envato::ClientError
        when 500..599 then raise Envato::ServerError, extract_server_error_message(response)
      end

      begin
        JSON.parse(response.body)
      rescue JSON::ParserError
        response.body
      end
    end

    def extract_forbidden_message(response)
      body = JSON.parse(response.body)
      body['error_description'] if body['error_description']
    end

    def extract_not_found_message(response)
      body = JSON.parse(response.body)
      body['description'] if body['description']
    end

    def extract_server_error_message(response)
      body = JSON.parse(response.body)
      body['message'] if body['message']
    end
  end
end

{'fraction_non_alphanumeric': 0.0892018779342723, 'fraction_numerical': 0.013078470824949699, 'mean_word_length': 2.5301775147928995, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '7186935', 'n_tokens_mistral': 934, 'n_tokens_neox': 880, 'n_words': 220}