Exception: MisarMail::PlanLimitError
- 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
-
#feature ⇒ String?
readonly
The allowance that was exhausted.
-
#plan ⇒ String?
readonly
The account's current plan slug.
-
#retry_after ⇒ Integer?
readonly
Seconds until the allowance resets.
-
#upgrade_url ⇒ String?
readonly
Pricing page to send the user to.
Attributes inherited from ApiError
Instance Method Summary collapse
-
#initialize(status, message, body = nil, headers = {}) ⇒ PlanLimitError
constructor
A new instance of PlanLimitError.
Methods inherited from ApiError
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, , 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, , "plan_limit_exceeded") end |
Instance Attribute Details
#feature ⇒ String? (readonly)
Returns the allowance that was exhausted.
35 36 37 |
# File 'lib/misar_mail/errors.rb', line 35 def feature @feature end |
#plan ⇒ String? (readonly)
Returns the account's current plan slug.
29 30 31 |
# File 'lib/misar_mail/errors.rb', line 29 def plan @plan end |
#retry_after ⇒ Integer? (readonly)
Returns seconds until the allowance resets.
33 34 35 |
# File 'lib/misar_mail/errors.rb', line 33 def retry_after @retry_after end |
#upgrade_url ⇒ String? (readonly)
Returns pricing page to send the user to.
31 32 33 |
# File 'lib/misar_mail/errors.rb', line 31 def upgrade_url @upgrade_url end |