Sha256: f790bb3b86ea30d0286364e5ea65f39c5193af56d0926f80e0a687396ad63b8b

Contents?: true

Size: 734 Bytes

Versions: 2

Compression:

Stored size: 734 Bytes

Contents

module Fulfillment
  Error = Class.new(StandardError)

  # HTTP errors
  HttpError = Class.new(Error)
  ServerError = Class.new(HttpError)

  # Service errors
  class ServiceError < Error
    attr_reader :error

    def initialize(response_body = {})
      @error = response_body.fetch("error", {}) if response_body
    end

    def message
      error&.dig("message")
    end
    alias_method :to_s, :message

    def status
      error&.dig("status")
    end

    def type
      error&.dig("type")
    end
  end

  InvalidRequest = Class.new(ServiceError)
  InvalidEvent = Class.new(ServiceError)
  AccessDenied = Class.new(ServiceError)
  ResourceNotFound = Class.new(ServiceError)
  MethodNotAllowed = Class.new(ServiceError)
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fulfillment-api-1.1.9 lib/fulfillment/errors.rb
fulfillment-api-1.1.7 lib/fulfillment/errors.rb