Sha256: 3391bcc2af38d76c5f109d914573e33abeaf2e1e819e4e37a3ad2abf3f343428

Contents?: true

Size: 1.66 KB

Versions: 13

Compression:

Stored size: 1.66 KB

Contents

module GovDelivery::TMS
  module Request
    # The generic TMS error class
    class Error < StandardError
      attr_reader :code

      def initialize(code)
        super("HTTP Error: #{code}")
        @code = code
      end
    end

    # Raised when a recipient list is still being constructed and a request is made to view the
    # recipient list for a message.
    class InProgress < StandardError;
    end
  end

  module Errors
    class ServerError < StandardError
      def initialize(response)
        super("TMS client encountered a server error: #{response.status} \n#{response.body}")
      end
    end
    class NoRelation < StandardError
      def initialize(rel = nil, obj = nil)
        message = 'no link relation '
        message << "'#{rel}' " if rel
        message << 'is available'
        message << " for #{obj}" if obj
        super(message)
      end
    end
    class InvalidVerb < StandardError
      attr_reader :record

      def initialize(record_or_string)
        if record_or_string.respond_to?(:href)
          @record = record_or_string
          super("Couldn't POST #{record.class} to #{record.href}: #{error_message}")
        else
          super(record_or_string)
        end
      end

      def error_message
        record.errors.map { |k, v| "#{k} #{v.join(' and ')}" }.join(', ')
      end
    end
    class InvalidPost < InvalidVerb
    end
    class InvalidPut < InvalidVerb
    end
    class InvalidDelete < InvalidVerb
    end
    class InvalidGet < StandardError
      def initialize(message = nil)
        super(message || "Can't GET a resource after an invalid POST; either create a new object or fix errors")
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
govdelivery-tms-3.0.0 lib/govdelivery/tms/errors.rb
govdelivery-tms-2.8.4 lib/govdelivery/tms/errors.rb
govdelivery-tms-2.8.3 lib/govdelivery/tms/errors.rb
govdelivery-tms-0.10.1 lib/govdelivery/tms/errors.rb
govdelivery-tms-0.10.0 lib/govdelivery/tms/errors.rb
govdelivery-tms-0.9.4 lib/govdelivery/tms/errors.rb
govdelivery-tms-0.9.3 lib/govdelivery/tms/errors.rb
govdelivery-tms-0.9.2 lib/govdelivery/tms/errors.rb
govdelivery-tms-0.9.0 lib/govdelivery/tms/errors.rb
govdelivery-tms-0.8.14 lib/govdelivery/tms/errors.rb
govdelivery-tms-0.8.13 lib/govdelivery/tms/errors.rb
govdelivery-tms-0.8.12 lib/govdelivery/tms/errors.rb
govdelivery-tms-0.8.11 lib/govdelivery/tms/errors.rb