Sha256: bc9986100ac4dbed0d2018e8ffe059ca9b9cca9b15670031b8a79ad7ea648cb6

Contents?: true

Size: 782 Bytes

Versions: 12

Compression:

Stored size: 782 Bytes

Contents

require 'travis/client'

module Travis
  module Client
    class Error < StandardError
    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

12 entries across 12 versions & 1 rubygems

Version Path
travis-1.7.2.travis.630.5 lib/travis/client/error.rb
travis-1.7.2.travis.627.5 lib/travis/client/error.rb
travis-1.7.2.travis.626.5 lib/travis/client/error.rb
travis-1.7.2.travis.625.5 lib/travis/client/error.rb
travis-1.7.2.travis.623.5 lib/travis/client/error.rb
travis-1.7.2.travis.621.5 lib/travis/client/error.rb
travis-1.7.1 lib/travis/client/error.rb
travis-1.7.1.travis.613.5 lib/travis/client/error.rb
travis-1.7.0 lib/travis/client/error.rb
travis-1.6.18.travis.612.5 lib/travis/client/error.rb
travis-1.6.18.travis.611.5 lib/travis/client/error.rb
travis-1.6.18.travis.610.5 lib/travis/client/error.rb