Add Forbidden error details

This commit is contained in:
Toby Zerner 2021-08-29 15:50:46 +10:00
parent 8584d1de9b
commit 589fa47f68
5 changed files with 20 additions and 5 deletions

View File

@ -33,7 +33,10 @@ class Create
$schema = $resourceType->getSchema(); $schema = $resourceType->getSchema();
if (! evaluate($schema->isCreatable(), [$context])) { if (! evaluate($schema->isCreatable(), [$context])) {
throw new ForbiddenException(); throw new ForbiddenException(sprintf(
'Cannot create resource type %s',
$resourceType->getType()
));
} }
$model = $this->newModel($resourceType, $context); $model = $this->newModel($resourceType, $context);

View File

@ -30,7 +30,11 @@ class Delete
$schema = $resourceType->getSchema(); $schema = $resourceType->getSchema();
if (! evaluate($schema->isDeletable(), [$model, $context])) { 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]); run_callbacks($schema->getListeners('deleting'), [&$model, $context]);

View File

@ -40,7 +40,10 @@ class Index
$schema = $resourceType->getSchema(); $schema = $resourceType->getSchema();
if (! evaluate($schema->isListable(), [$context])) { if (! evaluate($schema->isListable(), [$context])) {
throw new ForbiddenException(); throw new ForbiddenException(sprintf(
'Cannot list resource type %s',
$resourceType->getType()
));
} }
$query = $adapter->query(); $query = $adapter->query();

View File

@ -31,7 +31,11 @@ class Update
$schema = $resourceType->getSchema(); $schema = $resourceType->getSchema();
if (! evaluate($schema->isUpdatable(), [$model, $context])) { 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); $data = $this->parseData($resourceType, $context->getRequest()->getParsedBody(), $model);

View File

@ -22,7 +22,8 @@ class ForbiddenException extends DomainException implements ErrorProviderInterfa
return [ return [
new Error( new Error(
new Error\Title('Forbidden'), new Error\Title('Forbidden'),
new Error\Status($this->getJsonApiStatus()) new Error\Status($this->getJsonApiStatus()),
...($this->message ? [new Error\Detail($this->message)] : [])
) )
]; ];
} }