Skip to content

Commit a655295

Browse files
committed
Actually throw a 404 if one is specified
14f465f part 2
1 parent 14f465f commit a655295

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/resources/ElementResource.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use yii\base\BaseObject;
1818
use yii\base\Exception;
1919
use yii\base\InvalidConfigException;
20+
use yii\web\NotFoundHttpException;
2021

2122
/**
2223
* Element resource adapter class.
@@ -118,6 +119,10 @@ public function getResource(): ResourceInterface
118119
if ($this->one) {
119120
$element = $query->one();
120121

122+
if (!$element) {
123+
throw new NotFoundHttpException('No element exists that matches the endpoint criteria');
124+
}
125+
121126
$resource = new Item($element, $transformer, $this->resourceKey);
122127
} else if ($this->paginate) {
123128
// Create the paginator

0 commit comments

Comments
 (0)