Add Forbidden error details
This commit is contained in:
parent
8584d1de9b
commit
589fa47f68
|
|
@ -33,7 +33,10 @@ class Create
|
|||
$schema = $resourceType->getSchema();
|
||||
|
||||
if (! evaluate($schema->isCreatable(), [$context])) {
|
||||
throw new ForbiddenException();
|
||||
throw new ForbiddenException(sprintf(
|
||||
'Cannot create resource type %s',
|
||||
$resourceType->getType()
|
||||
));
|
||||
}
|
||||
|
||||
$model = $this->newModel($resourceType, $context);
|
||||
|
|
|
|||
|
|
@ -30,7 +30,11 @@ class Delete
|
|||
$schema = $resourceType->getSchema();
|
||||
|
||||
if (! evaluate($schema->isDeletable(), [$model, $context])) {
|
||||
throw new ForbiddenException();
|
||||
throw new ForbiddenException(sprintf(
|
||||
'Cannot delete resource %s:%s',
|
||||
$resourceType->getType(),
|
||||
$resourceType->getAdapter()->getId($model)
|
||||
));
|
||||
}
|
||||
|
||||
run_callbacks($schema->getListeners('deleting'), [&$model, $context]);
|
||||
|
|
|
|||
|
|
@ -40,7 +40,10 @@ class Index
|
|||
$schema = $resourceType->getSchema();
|
||||
|
||||
if (! evaluate($schema->isListable(), [$context])) {
|
||||
throw new ForbiddenException();
|
||||
throw new ForbiddenException(sprintf(
|
||||
'Cannot list resource type %s',
|
||||
$resourceType->getType()
|
||||
));
|
||||
}
|
||||
|
||||
$query = $adapter->query();
|
||||
|
|
|
|||
|
|
@ -31,7 +31,11 @@ class Update
|
|||
$schema = $resourceType->getSchema();
|
||||
|
||||
if (! evaluate($schema->isUpdatable(), [$model, $context])) {
|
||||
throw new ForbiddenException();
|
||||
throw new ForbiddenException(sprintf(
|
||||
'Cannot update resource %s:%s',
|
||||
$resourceType->getType(),
|
||||
$resourceType->getAdapter()->getId($model)
|
||||
));
|
||||
}
|
||||
|
||||
$data = $this->parseData($resourceType, $context->getRequest()->getParsedBody(), $model);
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@ class ForbiddenException extends DomainException implements ErrorProviderInterfa
|
|||
return [
|
||||
new Error(
|
||||
new Error\Title('Forbidden'),
|
||||
new Error\Status($this->getJsonApiStatus())
|
||||
new Error\Status($this->getJsonApiStatus()),
|
||||
...($this->message ? [new Error\Detail($this->message)] : [])
|
||||
)
|
||||
];
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue