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

Parameters:

  • message (String) (defaults to: "Server error occurred")

    the error message

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

    additional context information

  • status_code (Integer) (defaults to: 500)

    HTTP status code (5xx)



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

Parameters:

  • message (String) (defaults to: "Bad gateway")

    the error message

Returns:



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

Parameters:

  • message (String) (defaults to: "Gateway timeout")

    the error message

Returns:



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

Parameters:

  • message (String) (defaults to: "Internal server error")

    the error message

Returns:



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

Parameters:

  • message (String) (defaults to: "Service unavailable")

    the error message

Returns:



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