{"record":{"id":"22fa330e329b15cb","repo":"calcom/cal.diy","slug":"user-with-username-username-not-found","errorCode":null,"errorMessage":"User with username \"${username}\" not found","messagePattern":"User with username \"(.+?)\" not found","errorType":"http","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"apps/api/v2/src/platform/event-types/event-types_2024_04_15/services/event-types.service.ts","lineNumber":112,"sourceCode":"\n    const eventType = await this.eventTypesRepository.getUserEventTypeForAtom(\n      user,\n      isUserOrganizationAdmin,\n      eventTypeId\n    );\n\n    if (!eventType) {\n      return null;\n    }\n\n    this.checkUserOwnsEventType(user.id, eventType.eventType);\n    return eventType as { eventType: EventTypeOutput };\n  }\n\n  async getEventTypesPublicByUsername(username: string): Promise<EventTypesPublic> {\n    const user = await this.usersRepository.findByUsername(username);\n    if (!user) {\n      throw new NotFoundException(`User with username \"${username}\" not found`);\n    }\n\n    return await getEventTypesPublic(user.id);\n  }\n\n  async createUserDefaultEventTypes(userId: number) {\n    const { sixtyMinutes, sixtyMinutesVideo, thirtyMinutes, thirtyMinutesVideo } = DEFAULT_EVENT_TYPES;\n\n    const defaultEventTypes = await Promise.all([\n      this.eventTypesRepository.createUserEventType(userId, thirtyMinutes),\n      this.eventTypesRepository.createUserEventType(userId, sixtyMinutes),\n      this.eventTypesRepository.createUserEventType(userId, thirtyMinutesVideo),\n      this.eventTypesRepository.createUserEventType(userId, sixtyMinutesVideo),\n    ]);\n\n    return defaultEventTypes;\n  }\n","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/calcom/cal.diy/blob/176037d0afbe572f870a3c702985e7cd83fe6c0c/apps/api/v2/src/platform/event-types/event-types_2024_04_15/services/event-types.service.ts#L94-L130","documentation":"Thrown by EventTypesService_2024_04_15.getEventTypesPublicByUsername (GET /v2/event-types/:username/public) when usersRepository.findByUsername returns null — no user exists with that username. The endpoint is public/unauthenticated, so the username is the only key and a miss is a hard 404.","triggerScenarios":"GET /v2/event-types/janedoe/public where no user has username 'janedoe'; the username is correct but belongs to an organization and the org-scoped lookup requires a different path; username casing mismatch (the lookup may be case-sensitive depending on DB collation).","commonSituations":"Renamed or deleted users; typo in the username pulled from a URL or config; username includes the org prefix incorrectly; the user exists only in a different deployment (staging vs production).","solutions":["Confirm the username via the authenticated GET /v2/event-types or the user profile endpoint before calling the public route.","For organization users, supply the org context required by your deployment (subdomain or org query param).","Normalize the username to lowercase only if the repository lookup is case-insensitive — otherwise preserve exact casing.","Cache the list of valid usernames if you poll this endpoint frequently."],"exampleFix":"// before\nconst list = await api.get(`/v2/event-types/${username}/public`);\n// after\nconst profile = await api.get('/v2/me'); // confirms the authenticated user's username\nif (profile.username !== username) throw new Error('username mismatch');\nconst list = await api.get(`/v2/event-types/${username}/public`);","handlingStrategy":"validation","validationCode":"// Confirm the username exists via an authenticated profile lookup\nconst me = await api.get('/v2/me');\nif (me.username !== username) {\n  // either wrong user or not the authenticated user — check source of `username`\n  throw new Error(`username ${username} does not match an existing user`);\n}","typeGuard":"function isUsernameString(v: unknown): v is string {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  return await api.get(`/v2/event-types/${username}/public`);\n} catch (e) {\n  if (e.response?.status === 404) {\n    // no such user — prompt the user to correct the username\n  } else throw e;\n}","preventionTips":["Source usernames from authenticated endpoints rather than user input where possible.","For org users, supply the correct org context (subdomain or query param).","Avoid assuming case-insensitivity unless you have confirmed the DB collation."],"tags":["nestjs","not-found","event-types","public-api","rest-api"],"backgroundTag":null,"analyzedSha":"176037d0afbe572f870a3c702985e7cd83fe6c0c","analyzedAt":"2026-08-12T19:12:41.464Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}