yikart/AiToEarn · warning · BadRequestException

只能选择一个参数: channelId, id, mine

Error message

只能选择一个参数: channelId, id, mine

What it means

channelSections.list supports filtering by exactly one of channelId, id, or mine. The controller enforces this by counting non-empty parameters and throwing BadRequestException when more than one is supplied.

Source

Thrown at project/aitoearn-electron/server/src/modules/plat/youtube/youtube.controller.ts:188

  }

  @ApiOperation({ summary: '获取频道板块列表' })
  @Get('channels/sections/list')
  async getChannelSectionsList(
    @GetToken() token: TokenInfo,
    @Query('accountId') accountId: string,
    @Query('channelId') channelId?: string,
    @Query('id') id?: string,
    @Query('maxResults') maxResults?: string,
    @Query('mine') mine?: boolean,
    @Query('pageToken') pageToken?: string,
    ) {
    // 校验确保只有一个参数传递
    const params = [channelId, id, mine];
    const nonEmptyParams = params.filter(param => param !== undefined && param !== null && param !== '');

    if (nonEmptyParams.length > 1) {
      throw new BadRequestException('只能选择一个参数: channelId, id, mine');
    }
    const accessToken = await this.youtubeAuthService.getUserAccessToken(accountId);
    return this.youtubeService.getChannelSectionsList(accessToken, channelId, id, mine, maxResults, pageToken);
  }

  @ApiOperation({ summary: '创建频道板块' })
  @Post('channels/sections/insert')
  async channelsSectionsInsert(
    @GetToken() token: TokenInfo,
    @Body('accountId') accountId: string,
    @Body('snippet') snippet?: Record<string, any>,
    @Body('contentDetails') contentDetails?: Record<string, any>,
  ) {
    const accessToken = await this.youtubeAuthService.getUserAccessToken(accountId);
    return this.youtubeService.insertChannelSection(accessToken, snippet, contentDetails);
  }

  @ApiOperation({ summary: '更新频道版块' })

View on GitHub (pinned to d3aa8bea5b)

Solutions

  1. Pass only one filter parameter per call
  2. Remove default mine/channelId values from client request builders when another filter is used
  3. Use id alone (with maxResults/pageToken for pagination) when fetching specific sections

Example fix

// before
return this.youtubeService.getChannelSectionsList(accessToken, channelId, id, mine, maxResults, pageToken); // caller sent channelId AND mine
// after
// caller sends only one, e.g.
GET /api/plat/youtube/channelSections/list?accountId=acc1&channelId=UCxxx&maxResults=10
Defensive patterns

Strategy: validation

Validate before calling

const filters = { channelId, id, mine };
const count = Object.values(filters).filter(v => v !== undefined && v !== null && v !== '').length;
if (count > 1) throw new Error('Provide at most one of channelId, id, mine');

Try / catch

try {
  const sections = await api.get('/plat/youtube/channelSections/list', { params });
} catch (e) {
  if (e.response?.status === 400 && String(e.response.data?.message).includes('只能选择一个参数')) {
    params = prioritizeFilter(params, ['id', 'channelId', 'mine']);
  }
}

Prevention

When it happens

Trigger: Requesting GET channelSections/list with both channelId=UC... and mine=true, or id=SEC... together with channelId.

Common situations: Persisted query state accumulating filters across user interactions; automated callers always appending mine=true as default; API gateway injecting default params.

Related errors


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