Sha256: e15dbe3f8e18c43211ba6cc45a0cee0a61da7af31f0ce93a2770a83791a0a700

Contents?: true

Size: 1.18 KB

Versions: 16

Compression:

Stored size: 1.18 KB

Contents

module Fluffle
  module Errors
    class BaseError < StandardError
      def to_response
        {
          'code'    => self.code,
          'message' => self.message,
          'data'    => self.data
        }
      end
    end

    class TimeoutError < StandardError
    end

    # Raise this within your own code to get an error that will be faithfully
    # translated into the code, message, and data member fields of the
    # spec's `Error` response object
    class CustomError < BaseError
      attr_accessor :code, :data

      def initialize(code: 0, message:, data: nil)
        @code = code
        @data = data

        super message
      end
    end

    # Superclass of all errors that may be raised within the server
    class ServerError < BaseError
      # Longer-form description that may be present in the `data` field of
      # the `Error` response object
      attr_reader :description

      def data
        { 'description' => @description }
      end
    end

    class InvalidRequestError < ServerError
      def initialize(description)
        @description = description

        super 'Invalid Request'
      end

      def code
        -32600
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
fluffle-0.6.3 lib/fluffle/errors.rb
fluffle-0.6.2 lib/fluffle/errors.rb
fluffle-0.6.1 lib/fluffle/errors.rb
fluffle-0.6.0 lib/fluffle/errors.rb
fluffle-0.5.2 lib/fluffle/errors.rb
fluffle-0.5.1 lib/fluffle/errors.rb
fluffle-0.5.0 lib/fluffle/errors.rb
fluffle-0.4.0 lib/fluffle/errors.rb
fluffle-0.3.1 lib/fluffle/errors.rb
fluffle-0.3.0 lib/fluffle/errors.rb
fluffle-0.2.2 lib/fluffle/errors.rb
fluffle-0.2.1 lib/fluffle/errors.rb
fluffle-0.2.0 lib/fluffle/errors.rb
fluffle-0.1.1 lib/fluffle/errors.rb
fluffle-0.1.0 lib/fluffle/errors.rb
fluffle-0.0.3 lib/fluffle/errors.rb