Exception: MisarBlog::PlanLimitError
- Defined in:
- lib/misarblog/errors.rb
Overview
Raised when the subscription attached to the API key blocks the call.
The API signals this with code: "plan_limit_exceeded" and answers 429 when
a metered allowance is exhausted (retryable once the period rolls over) or
402 when the feature is locked outright. It is 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
-
#plan ⇒ String?
readonly
The account's current plan slug.
-
#retry_after ⇒ Integer?
readonly
Seconds until the allowance resets.
-
#upgrade ⇒ Hash
readonly
The full upgrade offer from the response body.
-
#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.
Constructor Details
#initialize(status, message, body = nil, headers = {}) ⇒ PlanLimitError
Returns a new instance of PlanLimitError.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/misarblog/errors.rb', line 31 def initialize(status, , body = nil, headers = {}) body ||= {} headers = (headers || {}).transform_keys { |k| k.to_s.downcase } @upgrade = body["upgrade"].is_a?(Hash) ? body["upgrade"] : {} @plan = headers["x-misar-plan"] || @upgrade.dig("current_plan", "slug") # Headers are authoritative; fall back to the offer body when a proxy has # stripped them. @upgrade_url = headers["x-misar-upgrade-url"] || @upgrade.dig("urls", "pricing") ra = headers["retry-after"] @retry_after = ra&.match?(/\A\d+\z/) ? ra.to_i : nil super(status, , "plan_limit_exceeded", body) end |
Instance Attribute Details
#plan ⇒ String? (readonly)
Returns the account's current plan slug.
23 24 25 |
# File 'lib/misarblog/errors.rb', line 23 def plan @plan end |
#retry_after ⇒ Integer? (readonly)
Returns seconds until the allowance resets.
27 28 29 |
# File 'lib/misarblog/errors.rb', line 27 def retry_after @retry_after end |
#upgrade ⇒ Hash (readonly)
Returns the full upgrade offer from the response body.
29 30 31 |
# File 'lib/misarblog/errors.rb', line 29 def upgrade @upgrade end |
#upgrade_url ⇒ String? (readonly)
Returns pricing page to send the user to.
25 26 27 |
# File 'lib/misarblog/errors.rb', line 25 def upgrade_url @upgrade_url end |