ErrorHandler
in package
Standardized error handling utilities.
Table of Contents
Methods
- assert() : void
- Assert condition or throw ServiceException.
- assertFound() : void
- Assert resource exists or throw not found.
- formatLogMessage() : string
- Format error message for logging.
- handle() : array<string|int, mixed>
- Handle exception and return appropriate response array.
- isDebugMode() : bool
- Check if debug mode is enabled.
- log() : void
- Log error and optionally rethrow.
- retry() : mixed
- Execute callback with retry logic.
- setDebugMode() : void
- Set debug mode for detailed error output.
- sfError() : string
- Create error response for Symfony action.
- silent() : mixed
- Execute callback with silent error handling (logs but doesn't fail).
- wrap() : mixed
- Execute callback with error handling.
Methods
assert()
Assert condition or throw ServiceException.
public
static assert(bool $condition, string $message[, int $code = 400 ]) : void
Parameters
- $condition : bool
- $message : string
- $code : int = 400
assertFound()
Assert resource exists or throw not found.
public
static assertFound(mixed $resource, string $name[, mixed $id = null ]) : void
Parameters
- $resource : mixed
- $name : string
- $id : mixed = null
formatLogMessage()
Format error message for logging.
public
static formatLogMessage(Throwable $e[, string $context = '' ]) : string
Parameters
- $e : Throwable
- $context : string = ''
Return values
stringhandle()
Handle exception and return appropriate response array.
public
static handle(Throwable $e[, string $context = '' ]) : array<string|int, mixed>
Parameters
- $e : Throwable
- $context : string = ''
Return values
array<string|int, mixed>isDebugMode()
Check if debug mode is enabled.
public
static isDebugMode() : bool
Return values
boollog()
Log error and optionally rethrow.
public
static log(Throwable $e[, string $context = '' ][, bool $rethrow = false ]) : void
Parameters
- $e : Throwable
- $context : string = ''
- $rethrow : bool = false
retry()
Execute callback with retry logic.
public
static retry(callable $callback[, int $attempts = 3 ][, int $delayMs = 100 ][, string $context = '' ]) : mixed
Parameters
- $callback : callable
- $attempts : int = 3
- $delayMs : int = 100
- $context : string = ''
setDebugMode()
Set debug mode for detailed error output.
public
static setDebugMode(bool $enabled) : void
Parameters
- $enabled : bool
sfError()
Create error response for Symfony action.
public
static sfError(Throwable $e[, string $context = '' ]) : string
Parameters
- $e : Throwable
- $context : string = ''
Return values
stringsilent()
Execute callback with silent error handling (logs but doesn't fail).
public
static silent(callable $callback[, mixed $default = null ][, string $context = '' ]) : mixed
Parameters
- $callback : callable
- $default : mixed = null
- $context : string = ''
wrap()
Execute callback with error handling.
public
static wrap(callable $callback[, string $context = '' ]) : mixed
Parameters
- $callback : callable
- $context : string = ''