{"record":{"id":"3b8fcd94145c8657","repo":"immich-app/immich","slug":"can-t-delete-a-missing-profile-image","errorCode":null,"errorMessage":"Can't delete a missing profile Image","messagePattern":"Can't delete a missing profile Image","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"warning","filePath":"server/src/services/user.service.ts","lineNumber":139,"sourceCode":"    const user = await this.userRepository.update(auth.user.id, {\n      profileImagePath,\n      profileChangedAt: new Date(),\n    });\n\n    const toDelete = [file.path, ...(oldPath ? [oldPath] : [])];\n    await this.jobRepository.queue({ name: JobName.FileDelete, data: { files: toDelete } });\n\n    return {\n      userId: user.id,\n      profileImagePath: user.profileImagePath,\n      profileChangedAt: user.profileChangedAt,\n    };\n  }\n\n  async deleteProfileImage(auth: AuthDto): Promise<void> {\n    const user = await this.findOrFail(auth.user.id, { withDeleted: false });\n    if (user.profileImagePath === '') {\n      throw new BadRequestException(\"Can't delete a missing profile Image\");\n    }\n    await this.userRepository.update(auth.user.id, { profileImagePath: '', profileChangedAt: new Date() });\n    await this.jobRepository.queue({ name: JobName.FileDelete, data: { files: [user.profileImagePath] } });\n  }\n\n  async getProfileImage(id: string): Promise<ImmichFileResponse> {\n    const user = await this.userRepository.get(id, {});\n    if (!user || !user.profileImagePath) {\n      this.logger.debug('User or profile image not found');\n      throw new NotFoundException();\n    }\n\n    return new ImmichFileResponse({\n      path: user.profileImagePath,\n      contentType: mimeTypes.lookup(user.profileImagePath),\n      cacheControl: CacheControl.None,\n    });\n  }","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/immich-app/immich/blob/e55ac299a4ec7cb372e35dbf2c6c05ee9ce77f6c/server/src/services/user.service.ts#L121-L157","documentation":"deleteProfileImage is called when the authenticated user has no profile image set (profileImagePath is the empty string). Deleting a nonexistent profile image is treated as a client error, so a 400 Bad Request is thrown before any update or file-delete job runs.","triggerScenarios":"DELETE /users/profile-image for a user whose profileImagePath === '' — i.e. the account never uploaded a profile photo, or it was already deleted (possibly by a concurrent request or the same client retrying).","commonSituations":"Client UI double-clicking the delete button; a stale client state showing a profile photo that was already removed in another tab/session; fresh accounts that never set a photo; scripts looping deletion over users.","solutions":["Check the user's profileImagePath (GET /users/me) before calling delete; skip the call when it is empty.","Treat the 400 with this message as an idempotent no-op in the client rather than surfacing it as an error.","If the UI shows a photo but the server says none exists, refresh user state — the image was already deleted elsewhere.","Guard delete buttons in the UI to be disabled when no profile photo is set."],"exampleFix":"// before\nawait api.deleteProfileImage();\n// after\nconst me = await api.getMyUser();\nif (me.profileImagePath) {\n  await api.deleteProfileImage();\n}","handlingStrategy":"validation","validationCode":"const me = await api.getMyUser();\nif (!me.profileImagePath) {\n  return; // nothing to delete\n}\nawait api.deleteProfileImage();","typeGuard":null,"tryCatchPattern":"try {\n  await api.deleteProfileImage();\n} catch (e) {\n  if (e instanceof BadRequestException && e.message.includes('missing profile Image')) {\n    return; // already deleted — treat as no-op\n  }\n  throw e;\n}","preventionTips":["Check profileImagePath before deleting.","Treat delete-as-missing as idempotent success in clients.","Refresh user state after any profile change to avoid stale UI.","Debounce delete buttons to prevent duplicate calls."],"tags":["profile-image","missing-resource","bad-request","idempotency"],"backgroundTag":"entity-not-found","analyzedSha":"e55ac299a4ec7cb372e35dbf2c6c05ee9ce77f6c","analyzedAt":"2026-09-15T07:20:19.675Z","contentChangedAt":"2026-09-15T07:20:19.675Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}