Sha256: 1a61c84c64075dc7189eeee6e688e4c73465275a6d4d73983bcfd8f9635e1cc5

Contents?: true

Size: 1.26 KB

Versions: 3

Compression:

Stored size: 1.26 KB

Contents

# coding: utf-8
# frozen_string_literal: true

module MicroRb
  module Servers
    class Error < StandardError
      attr_accessor :code, :message

      def initialize(code, message)
        self.code    = code
        self.message = message

        super(message)
      end

      def to_h
        { code: code, message: message }
      end

      class ParseError < Error
        def initialize
          super(-32_700, 'Invalid JSON was received by the server. '\
              'An error occurred on the server while parsing the JSON text.')
        end
      end

      class InvalidParams < Error
        def initialize
          super(-32_602, 'Invalid method parameter(s).')
        end
      end

      class ServerError < Error
        def initialize(code, message)
          super(code, message)
        end
      end

      class InvalidRequest < Error
        def initialize
          super(-32_600, 'The JSON sent is not a valid Request object.')
        end
      end

      class InternalError < Error
        def initialize(e)
          super(-32_603, "Internal server error: #{e}")
        end
      end

      class MethodNotFound < Error
        def initialize(method)
          super(-32_601, "Method '#{method}' not found.")
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
micro-rb-0.1.0.rc3 lib/micro/servers/error.rb
micro-rb-0.1.0.rc2 lib/micro/servers/error.rb
micro-rb-0.1.0.rc1 lib/micro/servers/error.rb