{"record":{"id":"98c0243c50fc0872","repo":"passbolt/passbolt_api","slug":"the-favorite-does-not-exist","errorCode":null,"errorMessage":"The favorite does not exist.","messagePattern":"The favorite does not exist\\.","errorType":"http","errorClass":"NotFoundException","httpStatus":404,"severity":"warning","filePath":"src/Service/Favorites/FavoritesDeleteService.php","lineNumber":57,"sourceCode":"    }\n\n    /**\n     * Unmarks a resource as favorite.\n     *\n     * @param string $id The identifier of favorite to delete.\n     * @param string|null $userId Currently authenticated user's ID. Used to determine\n     *                            if user can delete this favorite or not.\n     * @return void\n     * @throws \\Cake\\Http\\Exception\\NotFoundException When given ID doesn't exist.\n     * @throws \\Cake\\Http\\Exception\\BadRequestException When unable to delete the entity.\n     */\n    public function delete(string $id, ?string $userId): void\n    {\n        // Retrieve the favorite.\n        try {\n            $favorite = $this->Favorites->get($id);\n        } catch (RecordNotFoundException $e) {\n            throw new NotFoundException(__('The favorite does not exist.'), 404, $e);\n        }\n\n        // Delete the favorite.\n        $this->Favorites->delete($favorite, ['Favorites.user_id' => $userId]);\n        $this->_handleDeleteErrors($favorite);\n    }\n\n    /**\n     * Manage delete errors.\n     *\n     * @param \\App\\Model\\Entity\\Favorite $favorite Favorite entity.\n     * @return void\n     * @throws \\Cake\\Http\\Exception\\NotFoundException When user cannot delete this favorite entity.\n     * @throws \\Cake\\Http\\Exception\\BadRequestException When unable to delete the entity.\n     */\n    private function _handleDeleteErrors(Favorite $favorite): void\n    {\n        $errors = $favorite->getErrors();","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/src/Service/Favorites/FavoritesDeleteService.php#L39-L75","documentation":"FavoritesDeleteService::delete() looks up the favorite by its UUID with the Favorites table. When Table::get() finds no row it throws RecordNotFoundException, which is converted into this CakePHP NotFoundException (HTTP 404). It means no favorite exists with the given id (for the requesting user's visibility).","triggerScenarios":"Calling DELETE /favorites/{id} with an id that does not exist, was already deleted, or belongs to a favorite deleted in a prior request; also when the id is a valid UUID of a soft-deleted row.","commonSituations":"Client retries after a successful delete (double-tap), stale favorite ids cached in the UI after another user/resource removed them, or a race where two clients delete the same favorite concurrently.","solutions":["Verify the favorite id exists (GET the resource and check its favorite data) before calling delete","Treat 404 as idempotent success if the goal is 'ensure not favorited' and swallow this error client-side","Ensure the id passed is the favorite id, not the resource or user id"],"exampleFix":"// before\nawait deleteFavorite(someId);\n// after\ntry {\n  await deleteFavorite(someId);\n} catch (e) {\n  if (e.response?.status !== 404) throw e;\n}","handlingStrategy":"try-catch","validationCode":"const isUuid = (v) => /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(v);\nif (!isUuid(favoriteId)) throw new Error('invalid favorite id');","typeGuard":"const isUuid = (v: unknown): v is string =>\n  typeof v === 'string' && /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(v);","tryCatchPattern":"try {\n  await api.delete(`/favorites/${favoriteId}`);\n} catch (e) {\n  if (e.response?.status === 404) return; // already deleted, idempotent\n  throw e;\n}","preventionTips":["Treat 404 on favorite delete as success for idempotent un-favorite flows","Refresh favorite ids from resource data before each delete","Never reuse or guess favorite ids"],"tags":["http-404","favorites","rest-api"],"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"}