-
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathfault.rb
More file actions
51 lines (48 loc) · 1.37 KB
/
fault.rb
File metadata and controls
51 lines (48 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# frozen_string_literal: true
module Strava
module Errors
#
# Base error class for Strava API client errors.
#
# This exception is raised when the Strava API returns an error response.
# It extends Faraday::ClientError and provides convenient access to the
# error message, response headers, and detailed error information from
# the API response body.
#
# @see Faraday::ClientError
#
class Fault < ::Faraday::ClientError
#
# Returns the error message from the API response.
#
# Extracts the message from the response body if available,
# otherwise falls back to the parent class message.
#
# @return [String] The error message
#
def message
response[:body]['message'] || super
end
#
# Returns the HTTP response headers.
#
# @return [Hash] The response headers hash
#
def headers
response[:headers]
end
#
# Returns detailed error information from the API response.
#
# The Strava API may return an 'errors' array in the response body
# containing detailed information about validation errors or other
# specific error conditions.
#
# @return [Array, nil] Array of error details, or nil if not present
#
def errors
response[:body]['errors']
end
end
end
end