Method: Chatrix::Matrix#parse_response

Defined in:
lib/chatrix/matrix.rb

#parse_response(response) ⇒ HTTParty::Response (private)

Parses a HTTParty Response object and returns it if it was successful.

Parameters:

  • response (HTTParty::Response)

    The response object to parse.

Returns:

  • (HTTParty::Response)

    The same response object that was passed in, if the request was successful.

Raises:

  • (RequestError)

    If a 400 response code was returned from the request.

  • (AuthenticationError)

    If a 401 response code was returned from the request.

  • (ForbiddenError)

    If a 403 response code was returned from the request.

  • (NotFoundError)

    If a 404 response code was returned from the request.

  • (RateLimitError)

    If a 429 response code was returned from the request.

  • (ApiError)

    If an unknown response code was returned from the request.



258
259
260
261
262
263
264
265
266
# File 'lib/chatrix/matrix.rb', line 258

def parse_response(response)
  case response.code
  when 200 # OK
    response
  else
    handler = ERROR_HANDLERS[response.code]
    raise handler.first.new(response.parsed_response), handler.last
  end
end