Exception: Verikloak::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/verikloak/errors.rb

Overview

Base error class for all Verikloak-related exceptions.

All errors raised by this library inherit from this class so they can be rescued in a consistent way. Each error may carry a short, programmatic ‘code` (e.g., “invalid_token”, “jwks_fetch_failed”) that middleware and callers can use to map to HTTP statuses or telemetry.

Examples:

Raising with a code

raise Verikloak::Error.new("Something went wrong", code: "internal_error")

Raising with a code and HTTP status

raise Verikloak::Error.new("Forbidden", code: "forbidden", http_status: 403)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, code: nil, http_status: nil) ⇒ Error

Returns a new instance of Error.

Parameters:

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

    Human-readable error message.

  • code (String, Symbol, nil) (defaults to: nil)

    Optional short error code for programmatic handling.

  • http_status (Integer, nil) (defaults to: nil)

    Optional HTTP status code.



26
27
28
29
30
# File 'lib/verikloak/errors.rb', line 26

def initialize(message = nil, code: nil, http_status: nil)
  super(message)
  @code = code
  @http_status = http_status
end

Instance Attribute Details

#codeString, ... (readonly)

A short error code identifier suitable for programmatic handling.

Returns:

  • (String, Symbol, nil)

    the current value of code



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

def code
  @code
end

#http_statusInteger? (readonly)

HTTP status code associated with the error (e.g. 401, 403, 500, 503).

Returns:

  • (Integer, nil)

    the current value of http_status



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

def http_status
  @http_status
end