<commit_before>module Travis::API::V3
  class Queries::EnvVars < Query
    params :id, :name, :value, :public, prefix: :env_var

    def find(repository)
      repository.env_vars    
    end

    def create(repository)
      env_var = repository.env_vars.create(env_var_params)
      handle_errors(env_var) unless env_var.valid?
      repository.save!
      env_var
    end

    private

      def handle_errors(env_var)
        base = env_var.errors[:base]
        case
        when base.include?(:format)             then raise WrongParams
        when base.include?(:duplicate_resource) then raise DuplicateResource
        else                                         raise ServerError
        end
      end
  end
end
<commit_msg>Better style in error handling<commit_after>module Travis::API::V3
  class Queries::EnvVars < Query
    params :id, :name, :value, :public, prefix: :env_var

    def find(repository)
      repository.env_vars    
    end

    def create(repository)
      env_var = repository.env_vars.create(env_var_params)
      handle_errors(env_var) unless env_var.valid?
      repository.save!
      env_var
    end

    private

      def handle_errors(env_var)
        base = env_var.errors[:base]
        raise WrongParams       if base.include?(:format)
        raise DuplicateResource if base.include?(:duplicate_resource)
        raise ServerError
      end
  end
end

{'fraction_non_alphanumeric': 0.07587687902648532, 'fraction_numerical': 0.0014316392269148174, 'mean_word_length': 2.3768115942028984, 'pattern_counts': {'":': 0, '<': 5, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1350899', 'n_tokens_mistral': 413, 'n_tokens_neox': 401, 'n_words': 97}