yikart/AiToEarn · warning · AppException

ChannelPaginationLimitExceeded

ChannelPaginationLimitExceeded

Error message

ChannelPaginationLimitExceeded

What it means

ChannelPaginationLimitExceeded is thrown by normalizeChannelPagination when a cursor-mode pagination request's limit exceeds the platform's declared maxLimit. It guards against sending page sizes the upstream platform API would reject.

Source

Thrown at project/aitoearn-backend/apps/aitoearn-server/src/core/channels/platforms/platform-pagination.helper.ts:27

  pagination: ChannelPaginationInput,
): ChannelPaginationInput {
  const normalized = getDefaultPagination(metadata, pagination)
  const normalizedMode = getPaginationInputMode(normalized)

  if (metadata.mode !== normalizedMode) {
    throw new AppException(ResponseCode.ChannelPaginationModeNotSupported, {
      platform,
      expectedMode: metadata.mode,
      actualMode: normalizedMode,
    })
  }

  switch (normalizedMode) {
    case ChannelPaginationMode.Cursor: {
      const cursorMetadata = metadata as Extract<ChannelPaginationMetadata, { mode: ChannelPaginationMode.Cursor }>
      const limit = normalized.limit ?? cursorMetadata.defaultLimit
      if (limit > cursorMetadata.maxLimit) {
        throw new AppException(ResponseCode.ChannelPaginationLimitExceeded, {
          platform,
          limit,
          maxLimit: cursorMetadata.maxLimit,
        })
      }
      const direction = normalized.direction ?? ChannelPaginationDirection.Next
      if (direction === ChannelPaginationDirection.Previous && !cursorMetadata.supportsPrevious) {
        throw new AppException(ResponseCode.ChannelPaginationDirectionNotSupported, {
          platform,
          direction,
        })
      }
      return { ...normalized, limit, direction }
    }
    case ChannelPaginationMode.Page: {
      const pageMetadata = metadata as Extract<ChannelPaginationMetadata, { mode: ChannelPaginationMode.Page }>
      const pageSize = normalized.pageSize ?? pageMetadata.defaultPageSize
      if (pageSize > pageMetadata.maxPageSize) {

View on GitHub (pinned to d3aa8bea5b)

Solutions

  1. Clamp the limit to cursorMetadata.maxLimit before calling
  2. Omit limit to use the platform's defaultLimit
  3. Update client page-size presets to respect each platform's declared max

Example fix

// before
normalizeChannelPagination(platform, cursorMeta, { cursor, limit: 100 }) // maxLimit 50 -> throws
// after
const limit = Math.min(requestedLimit, cursorMeta.maxLimit)
normalizeChannelPagination(platform, cursorMeta, { cursor, limit })
Defensive patterns

Strategy: validation

Validate before calling

function clampLimit(limit: number | undefined, meta: { defaultLimit: number; maxLimit: number }): number {
  return Math.min(limit ?? meta.defaultLimit, meta.maxLimit)
}
const safePagination = { ...input, limit: clampLimit(input.limit, cursorMeta) }

Type guard

function isWithinLimit(limit: number | undefined, meta: { defaultLimit: number; maxLimit: number }): boolean {
  return (limit ?? meta.defaultLimit) <= meta.maxLimit
}

Try / catch

try {
  const page = await listChannelWorks(channelId, pagination)
} catch (e) {
  if (e instanceof AppException && e.code === ResponseCode.ChannelPaginationLimitExceeded) {
    const max = (e.context as { maxLimit: number }).maxLimit
    page = await listChannelWorks(channelId, { ...pagination, limit: max })
  } else throw e
}

Prevention

When it happens

Trigger: Calling normalizeChannelPagination with Cursor-mode metadata where (normalized.limit ?? cursorMetadata.defaultLimit) > cursorMetadata.maxLimit — e.g. requesting limit=100 against a platform whose maxLimit is 50.

Common situations: Clients with hardcoded large page sizes; UI 'load all' buttons clamping limits incorrectly; a platform lowering its max limit after an API version change while callers kept old values.

Related errors


AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31). Data as JSON: /api/errors/1f04204e8247fa7b. Report an issue: GitHub.