Exception: MisarMail::PlanLimitError

Inherits:
ApiError
  • Object
show all
Defined in:
lib/misar_mail/errors.rb

Overview

Raised when the subscription attached to the API key blocks the call.

MisarMail meters per-plan server-side: a spent allowance answers 429 and a feature not on the plan answers 402. Raised as its own class rather than a generic 429 because retrying cannot help until the allowance resets or the plan changes — the client stops retrying on sight.

Instance Attribute Summary collapse

Attributes inherited from ApiError

#error_type, #status

Instance Method Summary collapse

Methods inherited from ApiError

from_response

Constructor Details

#initialize(status, message, body = nil, headers = {}) ⇒ PlanLimitError

Returns a new instance of PlanLimitError.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/misar_mail/errors.rb', line 37

def initialize(status, message, body = nil, headers = {})
  body    ||= {}
  headers   = (headers || {}).transform_keys { |k| k.to_s.downcase }
  offer     = body["upgrade"].is_a?(Hash) ? body["upgrade"] : {}
  # Headers are authoritative; the offer body is the fallback when a proxy
  # has stripped them.
  @plan        = headers["x-misar-plan"] || offer["currentPlanSlug"] ||
                 offer.dig("current_plan", "slug")
  @upgrade_url = headers["x-misar-upgrade-url"] || offer.dig("urls", "pricing")
  ra           = headers["retry-after"]
  @retry_after = ra.to_s.match?(/\A\d+\z/) ? ra.to_i : nil
  @feature     = offer["feature"]
  super(status, message, "plan_limit_exceeded")
end

Instance Attribute Details

#featureString? (readonly)

Returns the allowance that was exhausted.

Returns:

  • (String, nil)

    the allowance that was exhausted



35
36
37
# File 'lib/misar_mail/errors.rb', line 35

def feature
  @feature
end

#planString? (readonly)

Returns the account's current plan slug.

Returns:

  • (String, nil)

    the account's current plan slug



29
30
31
# File 'lib/misar_mail/errors.rb', line 29

def plan
  @plan
end

#retry_afterInteger? (readonly)

Returns seconds until the allowance resets.

Returns:

  • (Integer, nil)

    seconds until the allowance resets



33
34
35
# File 'lib/misar_mail/errors.rb', line 33

def retry_after
  @retry_after
end

#upgrade_urlString? (readonly)

Returns pricing page to send the user to.

Returns:

  • (String, nil)

    pricing page to send the user to



31
32
33
# File 'lib/misar_mail/errors.rb', line 31

def upgrade_url
  @upgrade_url
end