passbolt/passbolt_api · error · BadRequestException

Could not delete favorite.

Error message

Could not delete favorite.

What it means

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.

Solutions

  1. Inspect the response body for the errors payload to identify the failing rule
  2. Run migrations (`ddev refresh`) to ensure schema matches the code expectations
  3. Reproduce locally and log $favorite->getErrors() after delete to see the concrete rule
  4. Check for customization in the Favorites table model rules
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await api.delete(`/favorites/${id}`);
} catch (e) {
  if (e.response?.status === 400) {
    console.error('Delete blocked, server errors:', e.response?.body || e.response?.data);
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of passbolt/passbolt_api@31c1bbc10f (2026-09-17). Data as JSON: /api/errors/02a4a763d49db980. Report an issue: GitHub.

Appendix: source

Thrown at src/Service/Favorites/FavoritesDeleteService.php:82

    /**
     * Manage delete errors.
     *
     * @param \App\Model\Entity\Favorite $favorite Favorite entity.
     * @return void
     * @throws \Cake\Http\Exception\NotFoundException When user cannot delete this favorite entity.
     * @throws \Cake\Http\Exception\BadRequestException When unable to delete the entity.
     */
    private function _handleDeleteErrors(Favorite $favorite): void
    {
        $errors = $favorite->getErrors();

        if (!empty($errors)) {
            if (isset($errors['user_id']['is_owner'])) {
                throw new NotFoundException(__('The favorite does not exist.'));
            }

            throw new BadRequestException(__('Could not delete favorite.'));
        }
    }
}

View on GitHub (pinned to 31c1bbc10f)