ServiceException
extends Exception
in package
Service Layer Exception for business logic errors.
Use this for recoverable errors in service classes.
Table of Contents
Methods
- __construct() : mixed
- badRequest() : self
- conflict() : self
- forbidden() : self
- getContext() : array<string|int, mixed>
- getStatusCode() : int
- getUserMessage() : string
- Get user-friendly message (safe to display).
- internal() : self
- notFound() : self
- toArray() : array<string|int, mixed>
- Convert to array for JSON response.
- unauthorized() : self
- validationFailed() : self
Methods
__construct()
public
__construct([string $message = '' ][, int $statusCode = 500 ][, array<string|int, mixed> $context = [] ][, string|null $userMessage = null ][, Throwable|null $previous = null ]) : mixed
Parameters
- $message : string = ''
- $statusCode : int = 500
- $context : array<string|int, mixed> = []
- $userMessage : string|null = null
- $previous : Throwable|null = null
badRequest()
public
static badRequest(string $message) : self
Parameters
- $message : string
Return values
selfconflict()
public
static conflict(string $message) : self
Parameters
- $message : string
Return values
selfforbidden()
public
static forbidden([string $reason = 'Permission denied' ]) : self
Parameters
- $reason : string = 'Permission denied'
Return values
selfgetContext()
public
getContext() : array<string|int, mixed>
Return values
array<string|int, mixed>getStatusCode()
public
getStatusCode() : int
Return values
intgetUserMessage()
Get user-friendly message (safe to display).
public
getUserMessage() : string
Return values
stringinternal()
public
static internal(string $message[, Throwable|null $previous = null ]) : self
Parameters
- $message : string
- $previous : Throwable|null = null
Return values
selfnotFound()
public
static notFound(string $resource[, mixed $id = null ]) : self
Parameters
- $resource : string
- $id : mixed = null
Return values
selftoArray()
Convert to array for JSON response.
public
toArray() : array<string|int, mixed>
Return values
array<string|int, mixed>unauthorized()
public
static unauthorized([string $reason = 'Authentication required' ]) : self
Parameters
- $reason : string = 'Authentication required'
Return values
selfvalidationFailed()
public
static validationFailed(array<string|int, mixed> $errors) : self
Parameters
- $errors : array<string|int, mixed>