Skip to main content

SupaProxyError

All non-ok responses throw a SupaProxyError:
import { SupaProxyClient, SupaProxyError } from '@supaproxy/sdk';

try {
  await client.workspaces.list();
} catch (err) {
  if (err instanceof SupaProxyError) {
    console.error(`Error ${err.status}: ${err.message}`);
  }
}

Properties

PropertyTypeDescription
statusnumberHTTP status code (e.g. 401, 404, 500)
messagestringError message from the API
namestringAlways 'SupaProxyError'

Common error codes

StatusMeaningExample message
400Validation error"name is required"
401Not authenticated"Not authenticated"
403Not authorised"Insufficient permissions"
404Not found"Workspace not found"
409Conflict"Channel already bound to another workspace"
500Server error"Internal server error"

Error handling patterns

React hooks

import { SupaProxyError } from '@supaproxy/sdk';

const [error, setError] = useState<string | null>(null);

try {
  const data = await api.workspaces.list();
  // handle success
} catch (err) {
  if (err instanceof SupaProxyError) {
    if (err.status === 401) {
      window.location.href = '/login';
    } else {
      setError(err.message);
    }
  }
}

AbortController

Cancelled requests do not throw SupaProxyError. They throw a native AbortError:
const controller = new AbortController();
controller.abort();

try {
  await api.workspaces.list({ signal: controller.signal });
} catch (err) {
  if (err instanceof DOMException && err.name === 'AbortError') {
    // Request was cancelled -- expected on unmount
  }
}

Known limitations

  • No automatic retry logic
  • No exponential backoff
  • No 429 rate limit handling
  • No request timeout configuration
  • No response caching