-
Notifications
You must be signed in to change notification settings - Fork 0
Application Error Codes
To get all the power of this package you may create your own class for your Application Error Codes that extends Mytdt\JsonApi\Errors\MyJsonApiErrors
. Your class will standardize errors for you application by defining constants and overriding the $errors
static property, like this:
use Mytdt\JsonApi\Errors\MyJsonApiErrors;
class AppErrorCodes extends MyJsonApiErrors
{
const PAGE_INVALID_PARAMETER = 1;
const RESOURCE_NOT_FOUND = 2;
const RESOURCE_UPDATE_FAILED = 3;
protected static $errors = [
self::PAGE_INVALID_PARAMETER => [
'title' => 'Invalid Parameter',
'detail' => 'The parameter given is invalid.',
'method' => 'queryParameter',
'parameter' => 'page'
],
self::RESOURCE_NOT_FOUND => [
'title' => 'Resource Not Found',
'detail' => 'The resource was not found.',
'method' => 'queryParameter',
'parameter' => 'resourceId'
],
self::RESOURCE_UPDATE_FAILED => [
'title' => 'Update Failed',
'detail' => 'Can not update the resource.'
]
];
}
By creating your own class, you can have your application codes completely standardized, generate a documentation of them through our package and also have support for localization.
First you need to define a constant to each application error code that you have. Second you need to add to $errors
static property an associative array with all information about this specific application error code.
This associative array can be compared with the JSON API Error Objects where each key
represent a member that Error Object may have. We will discuss this in the next chapter.