Class: Strava::Errors::RatelimitError

Inherits:
Faraday::ClientError
  • Object
show all
Defined in:
lib/strava/errors/ratelimit_error.rb

Overview

Exception raised when API rate limits are exceeded.

Strava enforces rate limits on API requests to prevent abuse. When your application exceeds these limits (either per 15 minutes or per day), the API returns a 429 Too Many Requests response, which triggers this exception.

This error includes rate limit information extracted from the response headers, allowing you to determine current usage and when limits will reset.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env, response) ⇒ RatelimitError

Initialize a new rate limit error.

Parameters:

  • env (Faraday::Env)

    The Faraday request environment

  • response (Hash)

    The HTTP response hash



28
29
30
31
# File 'lib/strava/errors/ratelimit_error.rb', line 28

def initialize(env, response)
  @ratelimit = Strava::Api::Ratelimit.new(env.response)
  super(response)
end

Instance Attribute Details

#ratelimitStrava::Api::Ratelimit (readonly)

Returns Rate limit information from response headers.

Returns:



20
21
22
# File 'lib/strava/errors/ratelimit_error.rb', line 20

def ratelimit
  @ratelimit
end

Instance Method Details

#errorsArray?

Returns detailed error information from the API response.

Returns:

  • (Array, nil)

    Array of error details, or nil if not present



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

def errors
  response[:body]['errors']
end

#headersHash

Returns the HTTP response headers.

Returns:

  • (Hash)

    The response headers hash



47
48
49
# File 'lib/strava/errors/ratelimit_error.rb', line 47

def headers
  response[:headers]
end

#messageString

Returns the error message from the API response.

Returns:

  • (String)

    The error message



38
39
40
# File 'lib/strava/errors/ratelimit_error.rb', line 38

def message
  response[:body]['message'] || super
end