Errors

Throw a code on the server, check it on the screen.

1 MIN READView Markdown ↗

Throw ApiError with a code and a message:

TypeScript
import { ApiError } from 'arkapi/server'

export function setNickname(name: string): string {
  if (isTaken(name)) throw new ApiError('CONFLICT', 'That nickname is taken')
  return save(name)
}

The code decides the HTTP status:

CodeStatus
BAD_REQUEST400
UNAUTHORIZED401
FORBIDDEN403
NOT_FOUND404
CONFLICT409
RATE_LIMITED429
INTERNAL500

Any other thrown error becomes INTERNAL, and its stack goes to the logs.

On the device, AsyncValue and LiveValue expose the same code as errorCode. Check the code, not the message text:

TypeScript
if (this.saved.errorCode === 'CONFLICT') {
  // ask for another nickname
}

NETWORK means the device could not reach the backend. A successful result clears error and errorCode.

Tab to navigate results · Enter to open · Esc to close