Exception: Poodle::ForbiddenError

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

Overview

Exception raised when access is forbidden (403 Forbidden)

Examples:

Handling forbidden errors

begin
  client.send_email(email)
rescue Poodle::ForbiddenError => e
  puts "Access forbidden: #{e.message}"
  puts "Reason: #{e.reason}" if e.reason
end

Instance Attribute Summary collapse

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 = "Access forbidden", reason: nil, context: {}) ⇒ ForbiddenError

Initialize a new ForbiddenError

Parameters:

  • message (String) (defaults to: "Access forbidden")

    the error message

  • reason (String, nil) (defaults to: nil)

    reason for the forbidden access

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

    additional context information



24
25
26
27
# File 'lib/poodle/errors/forbidden_error.rb', line 24

def initialize(message = "Access forbidden", reason: nil, context: {})
  @reason = reason
  super(message, context: context.merge(reason: reason), status_code: 403)
end

Instance Attribute Details

#reasonString? (readonly)

Returns reason for the forbidden access.

Returns:

  • (String, nil)

    reason for the forbidden access



17
18
19
# File 'lib/poodle/errors/forbidden_error.rb', line 17

def reason
  @reason
end

Class Method Details

.account_suspended(reason, rate = nil) ⇒ ForbiddenError

Create a ForbiddenError for account suspended

Parameters:

  • reason (String)

    the suspension reason

  • rate (Float, nil) (defaults to: nil)

    the suspension rate if applicable

Returns:



34
35
36
37
38
39
40
41
42
43
# File 'lib/poodle/errors/forbidden_error.rb', line 34

def self.(reason, rate = nil)
  message = "Account suspended: #{reason}"
  message += " (Rate: #{rate})" if rate

  new(
    message,
    reason: reason,
    context: { error_type: "account_suspended", suspension_rate: rate }
  )
end

.insufficient_permissionsForbiddenError

Create a ForbiddenError for insufficient permissions

Returns:



48
49
50
51
52
53
54
# File 'lib/poodle/errors/forbidden_error.rb', line 48

def self.insufficient_permissions
  new(
    "API key does not have sufficient permissions for this operation.",
    reason: "insufficient_permissions",
    context: { error_type: "insufficient_permissions" }
  )
end