Exception: BrainzLab::RateLimitError
- Defined in:
- lib/brainzlab/errors.rb
Overview
Raised when the rate limit for API requests has been exceeded.
Constant Summary
Constants inherited from Error
Instance Attribute Summary collapse
-
#limit ⇒ Integer?
readonly
The rate limit ceiling.
-
#remaining ⇒ Integer?
readonly
Remaining requests in the current window.
-
#retry_after ⇒ Integer?
readonly
Seconds to wait before retrying.
Attributes inherited from Error
#code, #context, #docs_url, #hint
Instance Method Summary collapse
-
#initialize(message = nil, hint: nil, docs_url: nil, code: nil, context: nil, retry_after: nil, limit: nil, remaining: nil) ⇒ RateLimitError
constructor
A new instance of RateLimitError.
Methods inherited from Error
#as_json, #detailed_message, #inspect, #to_h, #to_s
Constructor Details
#initialize(message = nil, hint: nil, docs_url: nil, code: nil, context: nil, retry_after: nil, limit: nil, remaining: nil) ⇒ RateLimitError
Returns a new instance of RateLimitError.
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/brainzlab/errors.rb', line 185 def initialize( = nil, hint: nil, docs_url: nil, code: nil, context: nil, retry_after: nil, limit: nil, remaining: nil) @retry_after = retry_after @limit = limit @remaining = remaining hint ||= retry_after ? "Wait #{retry_after} seconds before retrying" : 'Reduce request frequency or upgrade your plan' docs_url ||= "#{DOCS_BASE_URL}/sdk/ruby/rate-limits" code ||= 'rate_limit_exceeded' context ||= {} context[:retry_after] = retry_after if retry_after context[:limit] = limit if limit context[:remaining] = remaining if remaining super(, hint: hint, docs_url: docs_url, code: code, context: context.empty? ? nil : context) end |
Instance Attribute Details
#limit ⇒ Integer? (readonly)
Returns The rate limit ceiling.
180 181 182 |
# File 'lib/brainzlab/errors.rb', line 180 def limit @limit end |
#remaining ⇒ Integer? (readonly)
Returns Remaining requests in the current window.
183 184 185 |
# File 'lib/brainzlab/errors.rb', line 183 def remaining @remaining end |
#retry_after ⇒ Integer? (readonly)
Returns Seconds to wait before retrying.
177 178 179 |
# File 'lib/brainzlab/errors.rb', line 177 def retry_after @retry_after end |