Module: Genius::Errors
- Included in:
- Songs
- Defined in:
- lib/genius/api/errors.rb
Overview
Genius::Errors module includes custom exception classes and methods to handle all errors during requests to api.genius.com or during the work with library methods.
Exception classes fields provide custom message and error types (connection_error, token_error, auth_required, etc.)
There will be a standard output of each exception if there will be no params provided.
Defined Under Namespace
Modules: DynamicRescue Classes: GeniusExceptionSuperClass, LyricsNotFoundError, PageNotFound, TokenError
Constant Summary collapse
Class Method Summary collapse
-
.error_handle?(token, method_name: nil) ⇒ Boolean
deprecated
Deprecated.
Use Errors.validate_token instead.
-
.validate_token(token, method_name: nil) ⇒ void
Validates the access token by checking length and making a test request to the API.
Class Method Details
.error_handle?(token, method_name: nil) ⇒ Boolean
Use validate_token instead.
Validates token and raises on failure. Returns true if valid.
180 181 182 183 184 185 186 187 188 189 |
# File 'lib/genius/api/errors.rb', line 180 def error_handle?(token, method_name: nil) if token.nil? raise TokenError.new(msg: 'Token is required for this method. Please, add token via ' \ "`Genius::Auth.login=``token''` method and continue", method_name: method_name) elsif token.size != 64 || check_status?(token) == false raise TokenError.new(method_name: method_name) end true end |
.validate_token(token, method_name: nil) ⇒ void
This method returns an undefined value.
Validates the access token by checking length and making a test request to the API.
165 166 167 168 169 170 171 |
# File 'lib/genius/api/errors.rb', line 165 def validate_token(token, method_name: nil) raise TokenError.new(method_name: method_name) if token.nil? || token.size != 64 response = HTTParty.get("#{ENDPOINT}=#{token}").body status = JSON.parse(response).dig('meta', 'status') raise TokenError.new(method_name: method_name) unless status == 200 end |