Exception: MisarBlog::PlanLimitError

Inherits:
ApiError
  • Object
show all
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

Attributes inherited from ApiError

#body, #error_type, #status

Instance Method Summary collapse

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, message, 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, message, "plan_limit_exceeded", body)
end

Instance Attribute Details

#planString? (readonly)

Returns the account's current plan slug.

Returns:

  • (String, nil)

    the account's current plan slug



23
24
25
# File 'lib/misarblog/errors.rb', line 23

def plan
  @plan
end

#retry_afterInteger? (readonly)

Returns seconds until the allowance resets.

Returns:

  • (Integer, nil)

    seconds until the allowance resets



27
28
29
# File 'lib/misarblog/errors.rb', line 27

def retry_after
  @retry_after
end

#upgradeHash (readonly)

Returns the full upgrade offer from the response body.

Returns:

  • (Hash)

    the full upgrade offer from the response body



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

def upgrade
  @upgrade
end

#upgrade_urlString? (readonly)

Returns pricing page to send the user to.

Returns:

  • (String, nil)

    pricing page to send the user to



25
26
27
# File 'lib/misarblog/errors.rb', line 25

def upgrade_url
  @upgrade_url
end