<commit_before>module QualtricsAPI

  class RequestErrorHandler < Faraday::Response::Middleware

    def on_complete(env)
      case env[:status]
      when 404
        raise NotFoundError, "Not Found"
      when 400
        raise BadRequestError, error_message(JSON.parse(env[:body]))
      end
    end

    private

    def error_message(response)
      meta = response["meta"]
      [ "[",
        meta["status"], " - ",
        meta["qualtricsErrorCode"],
        "] ",
        meta["errorMessage"]
      ].join
    end

  end

  class NotFoundError < StandardError; end
  class BadRequestError < StandardError; end

end
<commit_msg>add 401 and 500 errors<commit_after>module QualtricsAPI

  class RequestErrorHandler < Faraday::Response::Middleware

    def on_complete(env)
      case env[:status]
      when 404
        raise NotFoundError, "Not Found"
      when 400
        raise BadRequestError, error_message(JSON.parse(env[:body]))
      when 401
        raise UnauthorizedError, error_message(JSON.parse(env[:body]))
      when 500
        raise InternalServerError, error_message(JSON.parse(env[:body]))
      end
    end

    private

    def error_message(response)
      meta = response["meta"]
      [ "[",
        meta["status"], " - ",
        meta["qualtricsErrorCode"],
        "] ",
        meta["errorMessage"]
      ].join
    end

  end

  class NotFoundError < StandardError; end
  class BadRequestError < StandardError; end
  class UnauthorizedError < StandardError; end
  class InternalServerError < StandardError; end

end

{'fraction_non_alphanumeric': 0.0978750804893754, 'fraction_numerical': 0.015453960077269801, 'mean_word_length': 2.691211401425178, 'pattern_counts': {'":': 0, '<': 11, '<?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': '4880766', 'n_tokens_mistral': 465, 'n_tokens_neox': 428, 'n_words': 106}