{"record":{"id":"02a4a763d49db980","repo":"passbolt/passbolt_api","slug":"could-not-delete-favorite","errorCode":null,"errorMessage":"Could not delete favorite.","messagePattern":"Could not delete favorite\\.","errorType":"http","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"src/Service/Favorites/FavoritesDeleteService.php","lineNumber":82,"sourceCode":"\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();\n\n        if (!empty($errors)) {\n            if (isset($errors['user_id']['is_owner'])) {\n                throw new NotFoundException(__('The favorite does not exist.'));\n            }\n\n            throw new BadRequestException(__('Could not delete favorite.'));\n        }\n    }\n}\n","sourceCodeStart":64,"sourceCodeEnd":86,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/src/Service/Favorites/FavoritesDeleteService.php#L64-L86","documentation":"FavoritesDeleteService throws this BadRequestException (HTTP 400) when the delete produced validation errors that are NOT the ownership rule — i.e. an unexpected entity-level validation failure blocked the deletion of the favorite.","triggerScenarios":"Favorites table delete() sets unexpected validation errors on the entity (e.g. database rule failures, integrity rules) other than user_id.is_owner, after a DELETE /favorites/{id} call.","commonSituations":"Database constraint/plugin customization altered favorite validation rules; data corruption where the favorite references a resource that no longer exists; version drift after an upgrade.","solutions":["Inspect the response body for the errors payload to identify the failing rule","Run migrations (`ddev refresh`) to ensure schema matches the code expectations","Reproduce locally and log $favorite->getErrors() after delete to see the concrete rule","Check for customization in the Favorites table model rules"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await api.delete(`/favorites/${id}`);\n} catch (e) {\n  if (e.response?.status === 400) {\n    console.error('Delete blocked, server errors:', e.response?.body || e.response?.data);\n  }\n  throw e;\n}","preventionTips":["Log the full 400 response body — the errors payload names the failing rule","Keep server schema/migrations in sync (`ddev refresh`) to avoid rule mismatches","Investigate custom Favorites table rules if this appears after upgrades"],"tags":["http-400","favorites","validation"],"backgroundTag":"database-write-failed","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"}