yikart/AiToEarn · error · AppException

InvalidWorkLink

InvalidWorkLink

Error message

InvalidWorkLink

What it means

getLinkInfo could not extract a Facebook work id from the normalized link. The URL resolved fine but parseFacebookWorkId returned null, meaning the link is not a recognized Facebook post/video/reel URL pattern.

Source

Thrown at project/aitoearn-backend/apps/aitoearn-server/src/core/channels/platforms/facebook/facebook-work.provider.ts:94

      || this.isImageType(attachment.type)
      || this.hasImageAttachment(attachment.subattachments?.data),
    ) ?? false
  }

  private isVideoType(type?: string): boolean {
    return !!type && type.toLowerCase().includes('video')
  }

  private isImageType(type?: string): boolean {
    const normalized = type?.toLowerCase()
    return normalized === 'photo' || normalized === 'image'
  }

  async getLinkInfo(input: WorkLinkInfoInput): Promise<ChannelWorkDataResult> {
    const resolvedUrl = await this.normalizeLink(input.link)
    const platformWorkId = this.parseFacebookWorkId(resolvedUrl)
    if (!platformWorkId) {
      throw new AppException(ResponseCode.InvalidWorkLink)
    }
    return {
      snapshots: [],
      work: {
        id: platformWorkId,
        url: resolvedUrl,
      },
    }
  }

  async getDetail(input: WorkDetailInput): Promise<ChannelWorkDataResult> {
    const post = await this.facebookService.getPostInfo(
      input.credential.accessToken,
      input.platformWorkId,
    )
    const fetchedAt = new Date()
    const createdAt = post.createdTime ? new Date(post.createdTime) : undefined
    const snapshot = {

View on GitHub (pinned to d3aa8bea5b)

Solutions

  1. Check the link is a supported Facebook post/video/reel permalink
  2. Ask the user to copy the canonical permalink (facebook.com/<page>/posts/<id> or /videos/<id>)
  3. Update parseFacebookWorkId to support the URL variant being pasted
  4. Log resolvedUrl to confirm what pattern reaches the parser
Defensive patterns

Strategy: validation

Validate before calling

const FB_WORK_RE = /facebook\.com\/(?:[^/]+\/(?:posts|videos|reels)\/\d+|watch\/?\?v=\d+|reel\/\d+)/
if (!FB_WORK_RE.test(input.link)) {
  throw new Error('Not a supported Facebook work link')
}

Type guard

function isFacebookWorkUrl(url: string): boolean {
  try { const u = new URL(url); return /(^|\.)facebook\.com$/.test(u.hostname) && /\d{5,}/.test(u.pathname + u.search) } catch { return false }
}

Prevention

When it happens

Trigger: Calling getLinkInfo with input.link that, after normalizeLink, contains no Facebook work id pattern (e.g. a facebook.com profile URL, a share link variant not supported by the regex, or a non-Facebook URL).

Common situations: Users paste mobile (m.facebook.com) or locale-prefixed links, share redirects, story links, or truncated URLs; plugin regex doesn't cover the newer /share/v/ or /reel/ formats.

Related errors


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