class Repro::Error

Public Class Methods

error_for_400(code) click to toggle source
# File lib/repro/error.rb, line 27
def self.error_for_400(code)
  case code
  when 1001; Repro::InvalidPayload
  when 1002; Repro::NotRegisteredUser
  when 1003; Repro::InvalidUserProfile
  else; Repro::BadRequest
  end
end
from_response(response) click to toggle source
# File lib/repro/error.rb, line 5
def self.from_response(response)
  body = JSON.parse(response.body)

  klass =
    case response.status
    when 400;      error_for_400(body.dig("error", "code"))
    when 401;      Repro::Unauthorized
    when 403;      Repro::Forbidden
    when 404;      Repro::NotFound
    when 422;      Repro::UnprocessableEntity
    when 429;      Repro::TooManyRequests
    when 400..499; Repro::ClientError
    end

  klass&.new(body)
end
new(response_body) click to toggle source
Calls superclass method
# File lib/repro/error.rb, line 22
def initialize(response_body)
  error_message = response_body.dig("error", "messages")&.join("\n")
  error_message ? super(error_message) : super
end