Exception: MatrixSdk::MatrixRequestError

Inherits:
MatrixError show all
Defined in:
lib/matrix_sdk/errors.rb

Overview

An error specialized and raised for failed requests

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error, status) ⇒ MatrixRequestError

Returns a new instance of MatrixRequestError.



29
30
31
32
33
34
35
36
# File 'lib/matrix_sdk/errors.rb', line 29

def initialize(error, status)
  @code = error[:errcode]
  @httpstatus = status
  @message = error[:error]
  @data = error.reject { |k, _v| %i[errcode error].include? k }

  super error[:error]
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



10
11
12
# File 'lib/matrix_sdk/errors.rb', line 10

def code
  @code
end

#dataObject (readonly)

Returns the value of attribute data.



10
11
12
# File 'lib/matrix_sdk/errors.rb', line 10

def data
  @data
end

#httpstatusObject (readonly)

Returns the value of attribute httpstatus.



10
11
12
# File 'lib/matrix_sdk/errors.rb', line 10

def httpstatus
  @httpstatus
end

#messageObject (readonly) Also known as: error

Returns the value of attribute message.



10
11
12
# File 'lib/matrix_sdk/errors.rb', line 10

def message
  @message
end

Class Method Details

.class_by_code(code) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/matrix_sdk/errors.rb', line 13

def self.class_by_code(code)
  code = code.to_i

  return MatrixNotAuthorizedError if code == 401
  return MatrixForbiddenError if code == 403
  return MatrixNotFoundError if code == 404
  return MatrixConflictError if code == 409
  return MatrixTooManyRequestsError if code == 429

  MatrixRequestError
end

.new_by_code(data, code) ⇒ Object



25
26
27
# File 'lib/matrix_sdk/errors.rb', line 25

def self.new_by_code(data, code)
  class_by_code(code).new(data, code)
end

Instance Method Details

#to_sObject



38
39
40
# File 'lib/matrix_sdk/errors.rb', line 38

def to_s
  "HTTP #{httpstatus} (#{code}): #{message}"
end