{"record":{"id":"834045fd247c2273","repo":"calcom/cal.diy","slug":"error-message","errorCode":null,"errorMessage":"${error.message}","messagePattern":"\\$\\{error\\.message\\}","errorType":"http","errorClass":"InternalServerErrorException","httpStatus":500,"severity":"error","filePath":"apps/api/v2/src/modules/selected-calendars/services/selected-calendars.service.ts","lineNumber":62,"sourceCode":"    await this.calendarsService.checkCalendarCredentials(Number(credentialId), user.id);\n\n    try {\n      const removedCalendarEntry = await this.selectedCalendarsRepository.removeUserSelectedCalendar(\n        user.id,\n        integration,\n        externalId,\n        undefined\n      );\n      await this.calendarsCacheService.deleteConnectedAndDestinationCalendarsCache(user.id);\n      return removedCalendarEntry;\n    } catch (error) {\n      if (error instanceof Error) {\n        if (error.message === NO_SELECTED_CALENDAR_FOUND) {\n          throw new NotFoundException(NO_SELECTED_CALENDAR_FOUND);\n        } else if (error.message === MULTIPLE_SELECTED_CALENDARS_FOUND) {\n          throw new BadRequestException(MULTIPLE_SELECTED_CALENDARS_FOUND);\n        } else {\n          throw new InternalServerErrorException(error.message);\n        }\n      }\n      throw new InternalServerErrorException(\n        \"An unexpected error occurred while deleting the selected calendar\"\n      );\n    }\n  }\n}\n","sourceCodeStart":44,"sourceCodeEnd":71,"githubUrl":"https://github.com/calcom/cal.diy/blob/176037d0afbe572f870a3c702985e7cd83fe6c0c/apps/api/v2/src/modules/selected-calendars/services/selected-calendars.service.ts#L44-L71","documentation":"InternalServerErrorException (HTTP 500) thrown when the selected-calendar deletion throws an Error instance whose message is neither NO_SELECTED_CALENDAR_FOUND nor MULTIPLE_SELECTED_CALENDARS_FOUND. The service surfaces the underlying error message verbatim as a generic 500, indicating an unexpected repository/database/infrastructure failure that the service does not know how to classify.","triggerScenarios":"Prisma throws a connection error, a constraint violation, a transaction abort, or a query timeout during removeUserSelectedCalendar; the cache service (deleteConnectedAndDestinationCalendarsCache) throws a Redis error before the catch is reached (note: the cache call is inside the try).","commonSituations":"Database connectivity loss mid-request, a Prisma schema migration that changed a column type, a Redis/valkey outage affecting the calendar cache, or an unmodeled Prisma error code (e.g. P2003 foreign-key constraint).","solutions":["Inspect server logs for the original error.message to identify the root cause (it is propagated here).","If it is a transient DB/cache error, retry the request after the infrastructure recovers.","Map the specific Prisma error code to a dedicated handler in the service so it no longer surfaces as a generic 500."],"exampleFix":"// before — only two known messages handled, everything else is a 500\n} else { throw new InternalServerErrorException(error.message); }\n// after — classify Prisma errors explicitly\n} else if (error instanceof Prisma.PrismaClientKnownRequestError) {\n  throw new ServiceUnavailableException('Database temporarily unavailable');\n} else {\n  throw new InternalServerErrorException(error.message);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"const isPrismaKnownError = (e: unknown): boolean =>\n  typeof e === 'object' && e !== null && 'code' in e && typeof (e as { code: unknown }).code === 'string' && /^P\\d+$/.test((e as { code: string }).code);","tryCatchPattern":"try { await api.delete(`/selected-calendars/${integration}/${externalId}`); }\ncatch (e) {\n  if (e.status >= 500) { /* log e.message, retry with backoff */ }\n  else throw e;\n}","preventionTips":["Map known Prisma error codes to specific handlers in the service instead of letting them surface as 500.","Monitor infrastructure (DB, Redis) health to catch the upstream cause early.","Log the original error.message server-side for diagnosis."],"tags":["selected-calendars","internal-error","database","nestjs","unhandled"],"backgroundTag":null,"analyzedSha":"176037d0afbe572f870a3c702985e7cd83fe6c0c","analyzedAt":"2026-08-12T19:12:41.464Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}