Skip to content

Commit f5885de

Browse files
committed
🐛 OAuth2::AccessToken Errors
- All errors raised are now OAuth2::Error - Improved error metadata - Improved inline documentation
1 parent 3c5fffc commit f5885de

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

lib/oauth2/access_token.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class << self
3434
# @note If no token keys are present, a warning will be issued unless
3535
# OAuth2.config.silence_no_tokens_warning is true
3636
# @note For "soon-to-expire"/"clock-skew" functionality see the `:expires_latency` option.
37-
# @mote If snaky key conversion is being used, token_name needs to match the converted key.
37+
# @note If snaky key conversion is being used, token_name needs to match the converted key.
3838
#
3939
# @example
4040
# hash = { 'access_token' => 'token_value', 'refresh_token' => 'refresh_value' }
@@ -125,8 +125,10 @@ def initialize(client, token, opts = {})
125125
no_tokens = (@token.nil? || @token.empty?) && (@refresh_token.nil? || @refresh_token.empty?)
126126
if no_tokens
127127
if @client.options[:raise_errors]
128-
error = Error.new(opts)
129-
raise(error)
128+
raise Error.new({
129+
error: "OAuth2::AccessToken has no token",
130+
error_description: "Options are: #{opts.inspect}",
131+
})
130132
elsif !OAuth2.config.silence_no_tokens_warning
131133
warn("OAuth2::AccessToken has no token")
132134
end
@@ -155,14 +157,14 @@ def [](key)
155157
@params[key]
156158
end
157159

158-
# Whether or not the token expires
160+
# Whether the token expires
159161
#
160162
# @return [Boolean]
161163
def expires?
162164
!!@expires_at
163165
end
164166

165-
# Whether or not the token is expired
167+
# Whether the token is expired
166168
#
167169
# @return [Boolean]
168170
def expired?
@@ -181,7 +183,7 @@ def refresh(params = {}, access_token_opts = {})
181183
new_token = @client.get_token(params, access_token_opts)
182184
new_token.options = options
183185
if new_token.refresh_token
184-
# Keep it, if there is one
186+
# Keep it if there is one
185187
else
186188
new_token.refresh_token = refresh_token
187189
end

0 commit comments

Comments
 (0)