Exception: MisarReach::UpgradeRequiredError

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

Overview

429 with upgrade: true — the workspace plan must be upgraded to proceed. A counted plan cap was hit.

MisarReach answers 402 with upgrade: true when a cap is reached and names the offending counter. Retrying cannot help until the cap resets or the plan changes.

Distinct from the 503 retry: true the server sends when it could not check the quota: that one is retried, so "we do not know" is never mistaken for "you are over your limit".

Constant Summary collapse

APP_ORIGIN =
"https://misarreach.com".freeze

Instance Attribute Summary collapse

Attributes inherited from ApiError

#body, #code, #retry_after, #status

Instance Method Summary collapse

Constructor Details

#initialize(message = "Upgrade required", **opts) ⇒ UpgradeRequiredError

Returns a new instance of UpgradeRequiredError.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/misar_reach/errors.rb', line 62

def initialize(message = "Upgrade required", **opts)
  body       = opts[:body] || {}
  @feature   = body["feature"]
  @limit     = body["limit"]
  @current   = body["current"]
  # The server sends an app-relative path; make it linkable.
  url = body["upgrade_url"]
  @upgrade_url =
    if url.nil? || url.start_with?("http://", "https://")
      url
    else
      APP_ORIGIN + (url.start_with?("/") ? url : "/#{url}")
    end
  super(opts[:status] || 402, message,
        code: opts[:code] || "upgrade_required",
        **opts.reject { |k, _| %i[code status].include?(k) })
end

Instance Attribute Details

#currentInteger? (readonly)

Returns usage against that cap when the call was refused.

Returns:

  • (Integer, nil)

    usage against that cap when the call was refused



58
59
60
# File 'lib/misar_reach/errors.rb', line 58

def current
  @current
end

#featureString? (readonly)

Returns the counter that was exhausted, e.g. "lead_searches".

Returns:

  • (String, nil)

    the counter that was exhausted, e.g. "lead_searches"



54
55
56
# File 'lib/misar_reach/errors.rb', line 54

def feature
  @feature
end

#limitInteger? (readonly)

Returns the cap on the current plan.

Returns:

  • (Integer, nil)

    the cap on the current plan



56
57
58
# File 'lib/misar_reach/errors.rb', line 56

def limit
  @limit
end

#upgrade_urlString? (readonly)

Returns absolute URL to the billing page.

Returns:

  • (String, nil)

    absolute URL to the billing page



60
61
62
# File 'lib/misar_reach/errors.rb', line 60

def upgrade_url
  @upgrade_url
end