Sha256: 9ba11856efa9e7802bf9da0df3156199a9ed15187dbba01e89739d2093b1b95e

Contents?: true

Size: 1.18 KB

Versions: 18

Compression:

Stored size: 1.18 KB

Contents

require 'travis/client'

module Travis
  module Client
    class Error < StandardError
    end

    class SSLError < Error
    end

    class NotFound < Error
    end

    class NotLoggedIn < Error
    end

    class InvalidTokenError < Error
    end

    class GitHubLoginFailed < Error
    end

    class RepositoryMigrated < Error
    end

    class AssetNotFound < Error
      def initialize(file, *args)
        if md = file.match(%r[init/(?<lang>[^\.]+)\.yml$])
          super "unknown language #{md[:lang]}", *args
        else
          super file, *args
        end
      end
    end

    class ValidationFailed < Error
      attr_reader :errors

      def initialize(message = nil, *args)
        message = parse_message(message) if message
        super(message, *args)
      end

      def parse_message(message)
        response   = JSON.load(message)
        message    = response['message'].to_s
        if @errors = response['errors'] and @errors.any?
          readable = @errors.map { |e| "#{e['field']}: #{e['code'].gsub('_', ' ')}" }
          message += " (#{readable.join(', ')})"
        end
        message
      rescue JSON::ParserError
        message
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
travis-1.11.1 lib/travis/client/error.rb
travis-1.11.0 lib/travis/client/error.rb
travis-1.10.1.travis.1341.9 lib/travis/client/error.rb
travis-1.10.1.travis.1321.9 lib/travis/client/error.rb
travis-1.10.1.travis.1312.9 lib/travis/client/error.rb
travis-1.10.1.travis.1311.9 lib/travis/client/error.rb
travis-1.10.1.travis.1305.9 lib/travis/client/error.rb
travis-1.10.0 lib/travis/client/error.rb
travis-1.9.2.travis.1304.9 lib/travis/client/error.rb
travis-1.9.2.travis.1303.9 lib/travis/client/error.rb
travis-1.10.0.pre.rc4 lib/travis/client/error.rb
travis-1.10.0.pre.rc3 lib/travis/client/error.rb
travis-1.10.0.pre.rc2 lib/travis/client/error.rb
travis-1.9.2.travis.1288.9 lib/travis/client/error.rb
travis-1.9.2.travis.1285.9 lib/travis/client/error.rb
travis-1.9.2.travis.1279.9 lib/travis/client/error.rb
travis-1.10.0.pre.rc1 lib/travis/client/error.rb
travis-1.9.2.travis.1254.9 lib/travis/client/error.rb