Exceptions
Introduction
By using exceptions we catch all unintended requests and handle them in a consistent way.
Error Codes
Error codes are defined as constants in Prest\Constants\ErrorCodes
:
Code | Constant | HTTP Status Code | Message |
---|---|---|---|
1010 | GENERAL_SYSTEM |
500 | General: System Error |
1020 | GENERAL_NOT_IMPLEMENTED |
500 | General: Not Implemented |
1030 | GENERAL_NOT_FOUND |
404 | General: Not Found |
2010 | AUTH_INVALID_ACCOUNT_TYPE |
400 | Authentication: Invalid Account Type |
2020 | AUTH_LOGIN_FAILED |
401 | Authentication: Login Failed |
2030 | AUTH_TOKEN_INVALID |
401 | Authentication: Token Invalid |
2040 | AUTH_SESSION_EXPIRED |
401 | Authentication: Session Expired |
2050 | AUTH_SESSION_INVALID |
401 | Authentication: Session Invalid |
3010 | ACCESS_DENIED |
403 | Access: Denied |
4010 | DATA_FAILED |
500 | Data: Failed |
4020 | DATA_NOT_FOUND |
404 | Data: Not Found |
5010 | POST_DATA_NOT_PROVIDED |
400 | Postdata: Not provided |
5020 | POST_DATA_INVALID |
400 | Postdata: Invalid |
Outputting Errors
try {
// Handle application
} catch (Exception $e) {
/** @var \Prest\Http\Response $response */
$response = $di->get(Services::RESPONSE);
// Second parameter enables debug mode (more error information)
$response->setErrorContent($e, true);
}