• English
  • Errors And Retries

    Planned APIs: This page documents error and recovery behavior after runtime release. commflow@0.0.2 does not provide request, SSE, RPC, or socket runtimes; see Current Release Quick Start for runnable exports.

    How To Use This Page

    First determine whether a call received a valid response, then choose retry, fallback, or business-level handling. For installation, imports, Node versions, or current exports, read Troubleshooting.

    Result Categories

    The error model distinguishes three outcomes:

    TypeDefault behaviorUser action
    HTTP 4xx/5xxrequest returns Response by defaultCheck response.ok or a failure helper.
    timeout / network / abortedthrows a structured errorUse error.kind for retry, alerting, or fallback.
    secondary hook failuredoes not replace the main resultRecord diagnostics.

    This avoids a common confusion: HTTP 500 is not necessarily a transport error; it is still an HTTP response from the server.

    Request Error Handling

    Recommended usage checks HTTP responses first, then catches real transport failures.

    try {
      const response = await request.get('/users/42');
    
      if (!response.ok) {
        return null;
      }
    
      return await response.json();
    } catch (error) {
      throw error;
    }

    Target error kinds:

    error.kindMeaningCommon action
    timeoutOne call exceeded timeoutRetry, alert, or fallback.
    networkDNS, connection, TLS, or socket failureRetry and record upstream address.
    abortedUser or host cancelled the requestUsually do not retry.
    configMissing or invalid configurationFix configuration; do not auto-retry.
    hookBlocking hook failedFix the hook and keep the original cause chain.

    Retry Policy

    More retry is not always better. Decide based on idempotency, whether the failure is temporary, and whether users can tolerate extra latency.

    ScenarioGuidance
    GET / HEADUsually safe for a small retry count.
    POST resource creationBe careful unless you have an idempotency key.
    payment, charging, inventory deductionDo not auto-retry unless the business protocol supports idempotency.
    SSE disconnectReconnect with a backoff policy.
    socket disconnectReconnect, but handle auth expiry and duplicate subscriptions.

    Minimum target configuration:

    const request = createCommflowRequestClient({
      retry: 2,
      retryDelay: (attempt) => attempt * 200
    });

    retry is the number of extra attempts. retryDelay is the wait before the next attempt. SSE and socket use reconnect, not the request retry field.

    Hook Secondary Failure

    Observer hooks such as afterResponse, onRetry, and onError should not turn an otherwise successful main request into a failure.

    HookTarget secondary failure behavior
    afterResponseRecord the failure, but return the original response.
    onRetryRecord the failure, but do not cancel the selected retry.
    onErrorRecord the failure, but do not replace the original error.

    Only request-building hooks such as beforeRequest should block dispatch when they throw.

    Troubleshooting Entry Points

    SymptomRead
    The current package has no createCommflowRequestClientTroubleshooting
    Unsure how to configure timeout or retryConfiguration
    Unsure whether to use request, SSE, RPC, or socketRuntime Guides
    VextJS behavior changes after replacing app.fetchVextJS Integration