Exception: AgentClientProtocol::RequestError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/agent_client_protocol/error.rb

Constant Summary collapse

PARSE_ERROR =
-32700
INVALID_REQUEST =
-32600
METHOD_NOT_FOUND =
-32601
INVALID_PARAMS =
-32602
INTERNAL_ERROR =
-32603
AUTH_REQUIRED =
-32000
RESOURCE_NOT_FOUND =
-32002

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, message, data = nil) ⇒ RequestError

Returns a new instance of RequestError.



15
16
17
18
19
# File 'lib/agent_client_protocol/error.rb', line 15

def initialize(code, message, data = nil)
  @code = code
  @data = data
  super(message)
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



5
6
7
# File 'lib/agent_client_protocol/error.rb', line 5

def code
  @code
end

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/agent_client_protocol/error.rb', line 5

def data
  @data
end

Class Method Details

.auth_required(data = nil) ⇒ Object



33
# File 'lib/agent_client_protocol/error.rb', line 33

def auth_required(data = nil)      = new(AUTH_REQUIRED, "Authentication required", data)

.from_hash(hash) ⇒ Object



36
37
38
# File 'lib/agent_client_protocol/error.rb', line 36

def from_hash(hash)
  new(hash["code"], hash["message"], hash["data"])
end

.internal_error(data = nil) ⇒ Object



32
# File 'lib/agent_client_protocol/error.rb', line 32

def internal_error(data = nil)     = new(INTERNAL_ERROR, "Internal error", data)

.invalid_params(data = nil) ⇒ Object



31
# File 'lib/agent_client_protocol/error.rb', line 31

def invalid_params(data = nil)     = new(INVALID_PARAMS, "Invalid params", data)

.invalid_request(data = nil) ⇒ Object



29
# File 'lib/agent_client_protocol/error.rb', line 29

def invalid_request(data = nil)    = new(INVALID_REQUEST, "Invalid request", data)

.method_not_found(method) ⇒ Object



30
# File 'lib/agent_client_protocol/error.rb', line 30

def method_not_found(method)       = new(METHOD_NOT_FOUND, "Method not found", {"method" => method})

.parse_error(data = nil) ⇒ Object



28
# File 'lib/agent_client_protocol/error.rb', line 28

def parse_error(data = nil)        = new(PARSE_ERROR, "Parse error", data)

.resource_not_found(uri = nil) ⇒ Object



34
# File 'lib/agent_client_protocol/error.rb', line 34

def resource_not_found(uri = nil)  = new(RESOURCE_NOT_FOUND, "Resource not found", uri ? {"uri" => uri} : nil)

Instance Method Details

#to_hObject



21
22
23
24
25
# File 'lib/agent_client_protocol/error.rb', line 21

def to_h
  h = {"code" => @code, "message" => message}
  h["data"] = @data if @data
  h
end