calcom/cal.diy · error · InternalServerErrorException

${error.message}

Error message

${error.message}

What it means

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.

Source

Thrown at apps/api/v2/src/modules/selected-calendars/services/selected-calendars.service.ts:62

    await this.calendarsService.checkCalendarCredentials(Number(credentialId), user.id);

    try {
      const removedCalendarEntry = await this.selectedCalendarsRepository.removeUserSelectedCalendar(
        user.id,
        integration,
        externalId,
        undefined
      );
      await this.calendarsCacheService.deleteConnectedAndDestinationCalendarsCache(user.id);
      return removedCalendarEntry;
    } catch (error) {
      if (error instanceof Error) {
        if (error.message === NO_SELECTED_CALENDAR_FOUND) {
          throw new NotFoundException(NO_SELECTED_CALENDAR_FOUND);
        } else if (error.message === MULTIPLE_SELECTED_CALENDARS_FOUND) {
          throw new BadRequestException(MULTIPLE_SELECTED_CALENDARS_FOUND);
        } else {
          throw new InternalServerErrorException(error.message);
        }
      }
      throw new InternalServerErrorException(
        "An unexpected error occurred while deleting the selected calendar"
      );
    }
  }
}

View on GitHub (pinned to 176037d0af)

Solutions

  1. Inspect server logs for the original error.message to identify the root cause (it is propagated here).
  2. If it is a transient DB/cache error, retry the request after the infrastructure recovers.
  3. Map the specific Prisma error code to a dedicated handler in the service so it no longer surfaces as a generic 500.

Example fix

// before — only two known messages handled, everything else is a 500
} else { throw new InternalServerErrorException(error.message); }
// after — classify Prisma errors explicitly
} else if (error instanceof Prisma.PrismaClientKnownRequestError) {
  throw new ServiceUnavailableException('Database temporarily unavailable');
} else {
  throw new InternalServerErrorException(error.message);
}
Defensive patterns

Strategy: try-catch

Type guard

const isPrismaKnownError = (e: unknown): boolean =>
  typeof e === 'object' && e !== null && 'code' in e && typeof (e as { code: unknown }).code === 'string' && /^P\d+$/.test((e as { code: string }).code);

Try / catch

try { await api.delete(`/selected-calendars/${integration}/${externalId}`); }
catch (e) {
  if (e.status >= 500) { /* log e.message, retry with backoff */ }
  else throw e;
}

Prevention

When it happens

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

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

Related errors


AI-assisted analysis of calcom/cal.diy@176037d0af (2026-08-12). Data as JSON: /api/errors/834045fd247c2273. Report an issue: GitHub.