passbolt/passbolt_api · error · NotFoundException
The resource does not exist.
Error message
The resource does not exist.
What it means
Passbolt throws this NotFoundException when the favorite entity fails validation specifically because the target resource does not exist, is soft-deleted, or the user lacks access (foreign_key errors resource_exists, resource_is_not_soft_deleted, has_resource_access). The generic message hides these three cases behind a single 404.
Solutions
- Verify the resource id exists and the current user has access before adding the favorite
- Refresh the resource list and drop references to deleted/inaccessible resources
- Retry with a valid foreign_key after re-syncing
Example fix
// before
$favoritesService->add($userId, ['foreign_key' => $staleResourceId, ...]);
// after
$resource = $resourcesTable->findVisible($userId)->where(['id' => $resourceId])->first();
if (!$resource) { return; }
$favoritesService->add($userId, ['foreign_key' => $resourceId, ...]); Defensive patterns
Strategy: validation
Validate before calling
$resource = $resourcesTable->findVisible($userId)
->where(['id' => $foreignKey, 'deleted' => false])->first();
$canFavorite = $resource !== null; Try / catch
try { $favoritesService->add($userId, $data); } catch (NotFoundException $e) { /* resource missing/deleted/no access */ } Prevention
- Only offer favorite actions on resources currently visible to the user
- Re-check resource existence after long-lived UI sessions
- Handle soft-deleted resources in client caches
When it happens
Trigger: Calling FavoritesAddService::add() with a foreign_key pointing to a deleted resource, a nonexistent id, or a resource the user cannot read.
Common situations: Client marking favorites on stale resource lists after another user deleted the resource; permission changes revoking access; soft-delete flows where the resource is hidden but still referenced.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- The folder does not exist.
- The resource does not exist.
- The resource does not exist.
- The resource does not exist.
- The resource does not exist.
AI-assisted analysis of passbolt/passbolt_api@31c1bbc10f (2026-09-17).
Data as JSON: /api/errors/32a9f4e2f8d33551.
Report an issue: GitHub.
Appendix: source
Thrown at src/Service/Favorites/FavoritesAddService.php:118
* Manage validation errors.
*
* @param \App\Model\Entity\Favorite $favorite favorite
* @throws \Cake\Http\Exception\BadRequestException if the record is already marked as favorite
* @throws \Cake\Http\Exception\NotFoundException if the resource does not exist
* @throws \App\Error\Exception\ValidationException if validation failed
* @return void
*/
protected function _handleValidationError(Favorite $favorite): void
{
$errors = $favorite->getErrors();
if (!empty($errors)) {
if (
isset($errors['foreign_key']['resource_exists'])
|| isset($errors['foreign_key']['resource_is_not_soft_deleted'])
|| isset($errors['foreign_key']['has_resource_access'])
) {
throw new NotFoundException(__('The resource does not exist.'));
}
if (isset($errors['user_id']['favorite_unique'])) {
throw new BadRequestException(__('This record is already marked as favorite.'));
}
throw new ValidationException(__('Could not validate favorite data.'));
}
}
}
View on GitHub (pinned to 31c1bbc10f)