moeru-ai/airi · error · Error

Failed to like character

Error message

Failed to like character

What it means

Thrown by CharactersService.likeRemote when POST /v1/characters/:id/like returns non-ok. The service expects a parseable character back (the liked state updated). Failure aborts parsing, so the like is not reflected.

Source

Thrown at packages/stage-ui/src/services/characters.ts:218

    const data = await res.json()
    options?.abortSignal?.throwIfAborted()
    return parse(data)
  }

  async function removeRemote(client: CharactersRemoteClient, id: string, options?: CharacterServiceOptions): Promise<void> {
    options?.abortSignal?.throwIfAborted()
    const res = await client.api.v1.characters[':id'].$delete({ param: { id } }, requestOptions(options))
    if (!res.ok)
      throw new Error('Failed to remove character')
    options?.abortSignal?.throwIfAborted()
  }

  async function likeRemote(client: CharactersRemoteClient, id: string, options?: CharacterServiceOptions): Promise<Character> {
    options?.abortSignal?.throwIfAborted()
    const res = await client.api.v1.characters[':id'].like.$post({ param: { id } }, requestOptions(options))
    if (!res.ok)
      throw new Error('Failed to like character')

    const data = await res.json()
    options?.abortSignal?.throwIfAborted()
    return parse(data)
  }

  async function bookmarkRemote(client: CharactersRemoteClient, id: string, options?: CharacterServiceOptions): Promise<Character> {
    options?.abortSignal?.throwIfAborted()
    const res = await client.api.v1.characters[':id'].bookmark.$post({ param: { id } }, requestOptions(options))
    if (!res.ok)
      throw new Error('Failed to bookmark character')

    const data = await res.json()
    options?.abortSignal?.throwIfAborted()
    return parse(data)
  }

  return {

View on GitHub (pinned to 27111382b4)

Solutions

  1. Handle 404 by refreshing the list and removing the stale character from the UI.
  2. Re-authenticate on 401/403 and retry the like once.
  3. On 409/already-liked, reconcile local state to 'liked' rather than erroring.
  4. Include res.status to enable status-based reconciliation.

Example fix

// before
if (!res.ok)
  throw new Error('Failed to like character')

// after
if (!res.ok) {
  if (res.status === 409) {
    // already liked; treat as success
    return parse(await res.json().catch(() => ({})))
  }
  throw new Error(`Failed to like character ${id} (status ${res.status})`)
}
Defensive patterns

Strategy: try-catch

Validate before calling

function isValidCharacterId(id: string): boolean {
  return typeof id === 'string' && id.length > 0
}

if (!isValidCharacterId(id))
  throw new Error(`Invalid character id: ${id}`)
await likeRemote(client, id)

Try / catch

try {
  return await likeRemote(client, id)
}
catch (error) {
  // Patch service to expose status; on 409 reconcile to 'liked', on 404 remove locally, on 401/403 re-auth.
  throw error
}

Prevention

When it happens

Trigger: client.api.v1.characters[':id'].like.$post({ param: { id } }) resolves with ok=false. Typical: 401/403 (not authenticated), 404 (character deleted), 409 (already liked / like constraint), 500 (server).

Common situations: Liking a character that was just deleted; session expired; double-like race where the backend rejects the second; permission to view but not interact.

Related errors


AI-assisted analysis of moeru-ai/airi@27111382b4 (2026-08-12). Data as JSON: /api/errors/ef89a6f62202750c. Report an issue: GitHub.