Exception: Poodle::ServerError

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

Overview

Exception raised when server errors occur (5xx status codes)

Examples:

Handling server errors

begin
  client.send_email(email)
rescue Poodle::ServerError => e
  puts "Server error: #{e.message}"
  puts "Status code: #{e.status_code}"
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 = "Server error occurred", context: {}, status_code: 500) ⇒ ServerError

Initialize a new ServerError



21
22
23
# File 'lib/poodle/errors/server_error.rb', line 21

def initialize(message = "Server error occurred", context: {}, status_code: 500)
  super(message, context: context.merge(error_type: "server_error"), status_code: status_code)
end

Class Method Details

.bad_gateway(message = "Bad gateway") ⇒ ServerError

Create a ServerError for bad gateway



37
38
39
# File 'lib/poodle/errors/server_error.rb', line 37

def self.bad_gateway(message = "Bad gateway")
  new(message, status_code: 502)
end

.gateway_timeout(message = "Gateway timeout") ⇒ ServerError

Create a ServerError for gateway timeout



53
54
55
# File 'lib/poodle/errors/server_error.rb', line 53

def self.gateway_timeout(message = "Gateway timeout")
  new(message, status_code: 504)
end

.internal_server_error(message = "Internal server error") ⇒ ServerError

Create a ServerError for internal server error



29
30
31
# File 'lib/poodle/errors/server_error.rb', line 29

def self.internal_server_error(message = "Internal server error")
  new(message, status_code: 500)
end

.service_unavailable(message = "Service unavailable") ⇒ ServerError

Create a ServerError for service unavailable



45
46
47
# File 'lib/poodle/errors/server_error.rb', line 45

def self.service_unavailable(message = "Service unavailable")
  new(message, status_code: 503)
end