Sha256: 1439e6c67ade3bee6b343bc3c765c95f4751f2029641ed1fdc090b689f9b6cbd

Contents?: true

Size: 865 Bytes

Versions: 65

Compression:

Stored size: 865 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 RepositoryMigrated < 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

65 entries across 65 versions & 1 rubygems

Version Path
travis-1.9.1.travis.1206.9 lib/travis/client/error.rb
travis-1.9.1.travis.1205.9 lib/travis/client/error.rb
travis-1.9.0 lib/travis/client/error.rb
travis-1.9.1.travis.1201.9 lib/travis/client/error.rb
travis-1.8.14.travis.1200.9 lib/travis/client/error.rb
travis-1.8.14.travis.1199.9 lib/travis/client/error.rb
travis-1.8.14.travis.1198.9 lib/travis/client/error.rb
travis-1.8.14.travis.1197.9 lib/travis/client/error.rb
travis-1.8.14.travis.1195.9 lib/travis/client/error.rb
travis-1.8.14.travis.1192.9 lib/travis/client/error.rb
travis-1.8.14.travis.1186.9 lib/travis/client/error.rb
travis-1.8.14.travis.1184.9 lib/travis/client/error.rb
travis-1.8.14.travis.1183.9 lib/travis/client/error.rb
travis-1.8.14.travis.1178.9 lib/travis/client/error.rb
travis-1.8.14.travis.1175.9 lib/travis/client/error.rb
travis-1.8.14.travis.1172.9 lib/travis/client/error.rb
travis-1.8.14.travis.1164.9 lib/travis/client/error.rb
travis-1.8.14.travis.1163.9 lib/travis/client/error.rb
travis-1.8.14.travis.1162.9 lib/travis/client/error.rb
travis-1.8.14.travis.1160.9 lib/travis/client/error.rb