protected function getObjectOr404($createOnNoId = false)
    {
        /** @var integer|null $objectId */
        $objectId = static::getObjectId();

        /** @var ObjectWrapperInterface $object */
        $object = null;

        if ($objectId !== null) {
            $object = $this->getQuery()->findOneByPrimaryKey($objectId);
        } elseif ($createOnNoId === true) {
            $object = $this->getQuery()->createObject();
        }

        if ($object === null) {
            http_response_code(404);
            throw new \Exception('Object not found.');
        }

        return $object;
    }