Exception: Poodle::AuthenticationError

Inherits:
Error
  • Object
show all
Defined in:
lib/poodle/errors/authentication_error.rb

Overview

Exception raised when API authentication fails (401 Unauthorized)

Examples:

Handling authentication errors

begin
  client.send_email(email)
rescue Poodle::AuthenticationError => e
  puts "Authentication failed: #{e.message}"
  puts "Please check your API key"
end

Instance Attribute Summary

Attributes inherited from Error

#context, #status_code

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Error

#message, #to_s

Constructor Details

#initialize(message = "Authentication failed", context: {}) ⇒ AuthenticationError

Initialize a new AuthenticationError

Parameters:

  • message (String) (defaults to: "Authentication failed")

    the error message

  • context (Hash) (defaults to: {})

    additional context information



20
21
22
# File 'lib/poodle/errors/authentication_error.rb', line 20

def initialize(message = "Authentication failed", context: {})
  super(message, context: context, status_code: 401)
end

Class Method Details

.expired_api_keyAuthenticationError

Create an AuthenticationError for expired API key

Returns:



47
48
49
50
51
52
# File 'lib/poodle/errors/authentication_error.rb', line 47

def self.expired_api_key
  new(
    "API key has expired. Please generate a new API key.",
    context: { error_type: "expired_api_key" }
  )
end

.invalid_api_keyAuthenticationError

Create an AuthenticationError for invalid API key

Returns:



27
28
29
30
31
32
# File 'lib/poodle/errors/authentication_error.rb', line 27

def self.invalid_api_key
  new(
    "Invalid API key provided. Please check your API key and try again.",
    context: { error_type: "invalid_api_key" }
  )
end

.missing_api_keyAuthenticationError

Create an AuthenticationError for missing API key

Returns:



37
38
39
40
41
42
# File 'lib/poodle/errors/authentication_error.rb', line 37

def self.missing_api_key
  new(
    "API key is required. Please provide a valid API key.",
    context: { error_type: "missing_api_key" }
  )
end