Exception: Hooks::Plugins::Handlers::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/hooks/plugins/handlers/error.rb

Overview

Custom exception class for handler errors

This exception is used when handlers call the ‘error!` method to immediately terminate request processing and return a specific error response. It carries the error details back to the Grape API context where it can be properly formatted and returned to the client.

Examples:

Usage in handler

error!({ error: "validation_failed", message: "Invalid payload" }, 400)

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, status = 500) ⇒ Error

Initialize a new handler error

Parameters:

  • body (Object)

    The error body/data to return to the client

  • status (Integer) (defaults to: 500)

    The HTTP status code to return (default: 500)



28
29
30
31
32
# File 'lib/hooks/plugins/handlers/error.rb', line 28

def initialize(body, status = 500)
  @body = body
  @status = status.to_i
  super("Handler error: #{status} - #{body}")
end

Instance Attribute Details

#bodyObject (readonly)

Returns The error body/data to return to the client.

Returns:

  • (Object)

    The error body/data to return to the client



19
20
21
# File 'lib/hooks/plugins/handlers/error.rb', line 19

def body
  @body
end

#statusInteger (readonly)

Returns The HTTP status code to return.

Returns:

  • (Integer)

    The HTTP status code to return



22
23
24
# File 'lib/hooks/plugins/handlers/error.rb', line 22

def status
  @status
end