Sha256: be04b4cdedba5f57f19b6678d90aabcf2980c3744ba0c2fe1919edcb2812609a

Contents?: true

Size: 818 Bytes

Versions: 111

Compression:

Stored size: 818 Bytes

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 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

111 entries across 111 versions & 3 rubygems

Version Path
travis-1.8.10.travis.994.9 lib/travis/client/error.rb
travis-1.8.10.travis.953.11 lib/travis/client/error.rb
travis-akerl-1.8.9.1 lib/travis/client/error.rb
travis-akerl-1.8.9 lib/travis/client/error.rb
travis-1.8.10.travis.950.11 lib/travis/client/error.rb
travis-1.8.10.travis.948.11 lib/travis/client/error.rb
travis-1.8.10.travis.946.11 lib/travis/client/error.rb
travis-1.8.10.travis.944.11 lib/travis/client/error.rb
travis-1.8.10.travis.943.11 lib/travis/client/error.rb
travis-1.8.10.travis.942.11 lib/travis/client/error.rb
travis-1.8.10.travis.941.11 lib/travis/client/error.rb
travis-1.8.10.travis.940.11 lib/travis/client/error.rb
travis-1.8.10.travis.935.11 lib/travis/client/error.rb
travis-1.8.10.travis.933.11 lib/travis/client/error.rb
travis-1.8.10.travis.931.11 lib/travis/client/error.rb
travis-1.8.10.travis.930.11 lib/travis/client/error.rb
travis-1.8.10.travis.929.11 lib/travis/client/error.rb
travis-1.8.10.travis.927.11 lib/travis/client/error.rb
travis-1.8.10.travis.925.11 lib/travis/client/error.rb
travis-1.8.10.travis.924.11 lib/travis/client/error.rb