Sha256: 99aaa92b6a7983a618cff19c80d8a68788e879357f5964960c49f66ebb3725d8

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

module Fluffle
  module Errors
    class BaseError < StandardError
      def to_response
        {
          'code'    => self.code,
          'message' => self.message,
          'data'    => self.data
        }
      end
    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 :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

2 entries across 2 versions & 1 rubygems

Version Path
fluffle-0.0.2 lib/fluffle/errors.rb
fluffle-0.0.1 lib/fluffle/errors.rb