immich-app/immich · warning · BadRequestException

Partner not found

Error message

Partner not found

What it means

PartnerService.remove looks up the partner record for the ordered pair (sharedById=caller, sharedWithId) and throws BadRequestException('Partner not found') when no such relation exists. Deletion is only allowed for a partnership that the caller established in this direction.

Solutions

  1. Refresh the partner list (GET /api/partners) and delete using a current partner ID.
  2. Note the direction: you can only remove partners you added; partners who added you are removed from their side or via the appropriate direction parameter.
  3. Treat 400 'Partner not found' as an idempotent success in retry logic.
  4. Verify the sharedWithId matches the user you intend to unshare with.

Example fix

// before
await api.partnersApi.removePartner({ id: partnerUserId }); // throws if already gone
// after
try {
  await api.partnersApi.removePartner({ id: partnerUserId });
} catch (e) {
  if (!String(e).includes('Partner not found')) throw e; // already removed — ignore
}
Defensive patterns

Strategy: try-catch

Validate before calling

const mine = await api.partnersApi.getPartners({ direction: 'shared-by' });
if (!mine.some((p) => p.userId === sharedWithId)) return; // nothing to remove

Try / catch

try {
  await api.partnersApi.removePartner({ id: sharedWithId });
} catch (e) {
  if (e.status === 400 && String(e.message).includes('Partner not found')) return; // already removed
  throw e;
}

Prevention

When it happens

Trigger: DELETE /api/partners/{sharedWithId} where the calling user has no partner record with that user as sharedWithId — wrong ID, already removed, or the partnership was created in the opposite direction.

Common situations: Retrying a delete after it already succeeded, stale UI listing, deleting a partner who added you (they own that record), or wrong user ID after a migration.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of immich-app/immich@e55ac299a4 (2026-09-15). Data as JSON: /api/errors/f58741da3db9bb45. Report an issue: GitHub.

Appendix: source

Thrown at server/src/services/partner.service.ts:33

    if (exists) {
      throw new BadRequestException(`Partner already exists`);
    }

    const user = await this.userRepository.get(sharedWithId, {});
    if (!user) {
      this.logger.debug('Partner creation failed: user not found');
      throw new BadRequestException('Invalid user');
    }

    const partner = await this.partnerRepository.create(partnerId);
    return this.mapPartner(partner, PartnerDirection.SharedBy);
  }

  async remove(auth: AuthDto, sharedWithId: string): Promise<void> {
    const partnerId: PartnerIds = { sharedById: auth.user.id, sharedWithId };
    const partner = await this.partnerRepository.get(partnerId);
    if (!partner) {
      throw new BadRequestException('Partner not found');
    }

    await this.partnerRepository.remove(partnerId);
  }

  async search(auth: AuthDto, { direction }: PartnerSearchDto): Promise<PartnerResponseDto[]> {
    const partners = await this.partnerRepository.getAll(auth.user.id);
    const key = direction === PartnerDirection.SharedBy ? 'sharedById' : 'sharedWithId';
    return partners
      .filter((partner): partner is Partner => !!(partner.sharedBy && partner.sharedWith)) // Filter out soft deleted users
      .filter((partner) => partner[key] === auth.user.id)
      .map((partner) => this.mapPartner(partner, direction));
  }

  async update(auth: AuthDto, sharedById: string, dto: PartnerUpdateDto): Promise<PartnerResponseDto> {
    await this.requireAccess({ auth, permission: Permission.PartnerUpdate, ids: [sharedById] });
    const partnerId: PartnerIds = { sharedById, sharedWithId: auth.user.id };

View on GitHub (pinned to e55ac299a4)