AuthException
extends LwtException
in package
Exception thrown when authentication is required but not present.
Tags
Table of Contents
Properties
- $context : array<string, mixed>
- Additional context data for logging/debugging.
- $httpStatusCode : int
- HTTP status code to return (for web responses).
- $shouldLog : bool
- Whether this exception should be logged.
Methods
- __construct() : mixed
- Create a new auth exception with appropriate HTTP status.
- accountDisabled() : self
- Create an exception for account disabled.
- getContext() : array<string, mixed>
- Get the context data for this exception.
- getHttpStatusCode() : int
- Get the HTTP status code for this exception.
- getUserMessage() : string
- Get a user-friendly message for display.
- insufficientPermissions() : self
- Create an exception for insufficient permissions.
- invalidApiToken() : self
- Create an exception for invalid API token.
- invalidCredentials() : self
- Create an exception for invalid credentials.
- sessionExpired() : self
- Create an exception for expired session.
- setHttpStatusCode() : self
- Set the HTTP status code.
- shouldLog() : bool
- Whether this exception should be logged.
- toArray() : array<string, mixed>
- Convert exception to array for logging/JSON responses.
- userNotAuthenticated() : self
- Create an exception for missing user context.
- withContext() : self
- Add context data to the exception.
Properties
$context
Additional context data for logging/debugging.
protected
array<string, mixed>
$context
= []
$httpStatusCode
HTTP status code to return (for web responses).
protected
int
$httpStatusCode
= 500
$shouldLog
Whether this exception should be logged.
protected
bool
$shouldLog
= true
Methods
__construct()
Create a new auth exception with appropriate HTTP status.
public
__construct([string $message = '' ][, int $code = 0 ]) : mixed
Parameters
- $message : string = ''
-
The exception message
- $code : int = 0
-
The exception code
accountDisabled()
Create an exception for account disabled.
public
static accountDisabled() : self
Return values
selfgetContext()
Get the context data for this exception.
public
getContext() : array<string, mixed>
Return values
array<string, mixed>getHttpStatusCode()
Get the HTTP status code for this exception.
public
getHttpStatusCode() : int
Return values
intgetUserMessage()
Get a user-friendly message for display.
public
getUserMessage() : string
Return values
stringinsufficientPermissions()
Create an exception for insufficient permissions.
public
static insufficientPermissions(string $action) : self
Parameters
- $action : string
-
The action that was denied
Return values
selfinvalidApiToken()
Create an exception for invalid API token.
public
static invalidApiToken() : self
Return values
selfinvalidCredentials()
Create an exception for invalid credentials.
public
static invalidCredentials() : self
Return values
selfsessionExpired()
Create an exception for expired session.
public
static sessionExpired() : self
Return values
selfsetHttpStatusCode()
Set the HTTP status code.
public
setHttpStatusCode(int $code) : self
Parameters
- $code : int
-
HTTP status code
Return values
selfshouldLog()
Whether this exception should be logged.
public
shouldLog() : bool
Return values
booltoArray()
Convert exception to array for logging/JSON responses.
public
toArray([bool $includeTrace = false ]) : array<string, mixed>
Parameters
- $includeTrace : bool = false
-
Whether to include stack trace
Return values
array<string, mixed>userNotAuthenticated()
Create an exception for missing user context.
public
static userNotAuthenticated() : self
Return values
selfwithContext()
Add context data to the exception.
public
withContext(string $key, mixed $value) : self
Parameters
- $key : string
-
Context key
- $value : mixed
-
Context value