OpenCode Network Error Parser (lib/opencode-errors.ts)

opencode-manager · frontend/src/lib/opencode-errors.ts · typescript · MIT
integration, infra, tag:error-handling

Parses and categorizes network fetch errors for the OpenCode API. Use this to provide user-friendly error messages and retry logic.

// Source: https://github.com/chriswritescode-dev/opencode-manager | License: MIT | Copyright 2025 Chris Scott
// Provided via justclaw.it.com; keep this notice with the code.
import { FetchError } from '@opencode-manager/shared'

export interface ParsedError {
  title: string
  message: string
  isRetryable: boolean
  statusCode?: number
}

export function isGatewayTimeout(error: unknown): boolean {
  return error instanceof FetchError && error.statusCode === 524
}

export function parseNetworkError(error: unknown): ParsedError {
  if (error instanceof Error) {
    if (error instanceof FetchError) {
      if (error.statusCode === 502) {
        return {
          title: 'Server Unavailable',
          message: 'The OpenCode server is not responding. It may need to be restarted.',
        

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key