yikart/AiToEarn · warning · AppException

ChannelPaginationModeNotSupported

ChannelPaginationModeNotSupported

Error message

ChannelPaginationModeNotSupported

What it means

ChannelPaginationModeNotSupported is thrown by normalizeChannelPagination when the pagination mode implied by the caller's input does not match the platform's declared ChannelPaginationMetadata.mode. Each platform declares cursor- or offset-based pagination; passing input that normalizes to the other mode is rejected.

Source

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

import type { AccountType } from '@yikart/common'
import type { ChannelPaginationInput, ChannelPaginationMetadata } from './platforms.interface'
import { AppException, ResponseCode } from '@yikart/common'
import { ChannelPaginationDirection, ChannelPaginationMode } from './platforms.interface'

export function normalizeChannelPagination(
  platform: AccountType,
  metadata: ChannelPaginationMetadata,
  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

View on GitHub (pinned to d3aa8bea5b)

Solutions

  1. Inspect the platform's pagination metadata and send matching fields (cursor for Cursor mode, page/limit for offset)
  2. Fix generic callers to branch on metadata.mode before building pagination input
  3. Use the provider's own default pagination (getDefaultPagination) as the shape template

Example fix

// before
normalizeChannelPagination(platform, meta, { cursor: 'abc' }) // meta.mode = Offset -> throws
// after
normalizeChannelPagination(platform, meta, { page: 1, limit: 20 }) // matches Offset mode
Defensive patterns

Strategy: type-guard

Validate before calling

function matchesPaginationMode(input: Record<string, unknown>, mode: ChannelPaginationMode): boolean {
  const hasCursor = typeof input.cursor === 'string'
  const hasOffset = typeof input.page === 'number' || typeof input.offset === 'number'
  return mode === ChannelPaginationMode.Cursor ? hasCursor : hasOffset
}
if (!matchesPaginationMode(input, metadata.mode)) throw new Error('Pagination mode mismatch')

Type guard

function isCursorPagination(p: unknown): p is { cursor: string; limit?: number } {
  return typeof p === 'object' && p !== null && typeof (p as any).cursor === 'string'
}

Try / catch

try {
  const page = await listChannelWorks(channelId, pagination)
} catch (e) {
  if (e instanceof AppException && e.code === ResponseCode.ChannelPaginationModeNotSupported) {
    // rebuild pagination from e.context.expectedMode and retry
  } else throw e
}

Prevention

When it happens

Trigger: Calling normalizeChannelPagination (directly or via a platform listing call) with pagination input whose mode (from getPaginationInputMode, e.g. cursor vs page/offset fields) differs from metadata.mode — e.g. sending { cursor } to a platform that declares offset pagination.

Common situations: Generic channel listing UI sending the same pagination shape to all platforms; platform metadata changed its declared mode; caller mixes cursor and offset fields in one request.

Related errors


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