{"record":{"id":"32a9f4e2f8d33551","repo":"passbolt/passbolt_api","slug":"the-resource-does-not-exist-favoritesaddservice","errorCode":null,"errorMessage":"The resource does not exist.","messagePattern":"The resource does not exist\\.","errorType":"http","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"src/Service/Favorites/FavoritesAddService.php","lineNumber":118,"sourceCode":"     * Manage validation errors.\n     *\n     * @param \\App\\Model\\Entity\\Favorite $favorite favorite\n     * @throws \\Cake\\Http\\Exception\\BadRequestException if the record is already marked as favorite\n     * @throws \\Cake\\Http\\Exception\\NotFoundException if the resource does not exist\n     * @throws \\App\\Error\\Exception\\ValidationException if validation failed\n     * @return void\n     */\n    protected function _handleValidationError(Favorite $favorite): void\n    {\n        $errors = $favorite->getErrors();\n\n        if (!empty($errors)) {\n            if (\n                isset($errors['foreign_key']['resource_exists'])\n                || isset($errors['foreign_key']['resource_is_not_soft_deleted'])\n                || isset($errors['foreign_key']['has_resource_access'])\n            ) {\n                throw new NotFoundException(__('The resource does not exist.'));\n            }\n\n            if (isset($errors['user_id']['favorite_unique'])) {\n                throw new BadRequestException(__('This record is already marked as favorite.'));\n            }\n\n            throw new ValidationException(__('Could not validate favorite data.'));\n        }\n    }\n}\n","sourceCodeStart":100,"sourceCodeEnd":129,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/src/Service/Favorites/FavoritesAddService.php#L100-L129","documentation":"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.","triggerScenarios":"Calling FavoritesAddService::add() with a foreign_key pointing to a deleted resource, a nonexistent id, or a resource the user cannot read.","commonSituations":"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.","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"],"exampleFix":"// before\n$favoritesService->add($userId, ['foreign_key' => $staleResourceId, ...]);\n// after\n$resource = $resourcesTable->findVisible($userId)->where(['id' => $resourceId])->first();\nif (!$resource) { return; }\n$favoritesService->add($userId, ['foreign_key' => $resourceId, ...]);","handlingStrategy":"validation","validationCode":"$resource = $resourcesTable->findVisible($userId)\n    ->where(['id' => $foreignKey, 'deleted' => false])->first();\n$canFavorite = $resource !== null;","typeGuard":null,"tryCatchPattern":"try { $favoritesService->add($userId, $data); } catch (NotFoundException $e) { /* resource missing/deleted/no access */ }","preventionTips":["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"],"tags":["not-found","favorites","permissions"],"backgroundTag":"resource-not-found","analyzedSha":"31c1bbc10f32808a607fa9bd81891e898779c0bc","analyzedAt":"2026-09-17T00:04:38.960Z","contentChangedAt":"2026-09-17T00:04:38.960Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}