Detailed Description
ApplicationError is used to signal errors that occur while processing a request.
This class allows to use predefined errors by using the ApplicationError::get() method. Errors are defined in the following way:
To use the error in the code:
Definition at line 41 of file ApplicationError.php.
Public Member Functions | |
getCode () | |
getLevel () | |
getStatusCode () | |
getMessage () | |
setData ($data) | |
getData () | |
__toString () | |
Static Public Member Functions | |
static | get ($code, $data=null) |
static | getGeneral ($message, $statusCode=self::DEFAULT_ERROR_STATUS) |
static | fromException (\Exception $ex) |
Public Attributes | |
const | LEVEL_WARNING = 'warning' |
const | LEVEL_ERROR = 'error' |
const | LEVEL_FATAL = 'fatal' |
const | DEFAULT_ERROR_STATUS = 500 |
Member Function Documentation
◆ getCode()
getCode | ( | ) |
◆ getLevel()
getLevel | ( | ) |
◆ getStatusCode()
getStatusCode | ( | ) |
Get the associated HTTP status code.
- Returns
- Integer
Definition at line 95 of file ApplicationError.php.
◆ getMessage()
getMessage | ( | ) |
◆ setData()
setData | ( | $data | ) |
Set the error data.
- Parameters
-
$data Some error codes require to transmit further information to the client
Definition at line 112 of file ApplicationError.php.
◆ getData()
getData | ( | ) |
◆ __toString()
__toString | ( | ) |
Get a string representation of the error.
- Returns
- String
Definition at line 128 of file ApplicationError.php.
◆ get()
|
static |
Factory method for retrieving a predefined error instance.
- Parameters
-
$code An error code $data Some error codes required to transmit further information to the client (optional, default: null)
- Returns
- ApplicationError
Definition at line 144 of file ApplicationError.php.
◆ getGeneral()
|
static |
Factory method for creating a general error instance.
- Parameters
-
$message Error message $statusCode HTTP status code (optional, default: DEFAULT_ERROR_STATUS)
- Returns
- ApplicationError
Definition at line 162 of file ApplicationError.php.
◆ fromException()
|
static |
Factory method for transforming an exception into an ApplicationError instance.
- Parameters
-
$ex Exception
- Returns
- ApplicationError
Definition at line 172 of file ApplicationError.php.
Member Data Documentation
◆ LEVEL_WARNING
const LEVEL_WARNING = 'warning' |
Definition at line 44 of file ApplicationError.php.
◆ LEVEL_ERROR
const LEVEL_ERROR = 'error' |
Definition at line 45 of file ApplicationError.php.
◆ LEVEL_FATAL
const LEVEL_FATAL = 'fatal' |
Definition at line 46 of file ApplicationError.php.
◆ DEFAULT_ERROR_STATUS
const DEFAULT_ERROR_STATUS = 500 |
Definition at line 48 of file ApplicationError.php.