hoppscotch/hoppscotch · error

typeof result.left === "string" ? result.left : result.left.

Error message

typeof result.left === "string" ? result.left : result.left.error.message

What it means

runTabGQLOperation executes the tab's GraphQL request via the relay/interceptor. When the transport resolves to an Either Left (network failure, non-2xx HTTP error, cancellation, or a structured kernel error), it sets the tab's error state and throws a plain Error whose message is either the left's string marker or left.error.message. This is the generic 'the GraphQL request itself failed at the transport level' error, distinct from GraphQL-level errors returned inside a 200 response.

Source

Thrown at packages/hoppscotch-common/src/services/gql-tab-connection.service.ts:1262

          ctx.error = {
            type: result.left.error?.kind || "error",
            message: (t: ReturnType<typeof getI18n>) => {
              if (
                result.left !== "cancellation" &&
                typeof result.left === "object"
              ) {
                return (
                  result.left.humanMessage?.description(t) ||
                  t("graphql.operation_error")
                )
              }
              return "Unknown"
            },
            component: result.left.component,
          }
        }

        throw new Error(
          typeof result.left === "string"
            ? result.left
            : result.left.error.message
        )
      }

      const relayResponse = result.right

      const parsedResponse = await GQLResponse.toResponse(
        relayResponse,
        options
      )

      if (parsedResponse.type === "error") {
        throw new Error(parsedResponse.error.message)
      }

      const timeEnd = Date.now()

View on GitHub (pinned to ac145e7f75)

Solutions

  1. Read the thrown message / result.left.error.message to identify transport vs HTTP cause.
  2. Confirm the endpoint URL and that the server is reachable (curl the GraphQL endpoint with the same operation).
  3. Refresh or fix credentials/headers — 401/403 here usually means auth config is wrong or expired.
  4. For 5xx, check server logs for the failing operation; retry after the backend issue is fixed.
  5. If the message is "cancellation", the run was superseded — rerun the operation if needed.

Example fix

// before
throw new Error(typeof result.left === "string" ? result.left : result.left.error.message)
// after
if (result.left === "cancellation") return
const detail = typeof result.left === "string" ? result.left : result.left.error.message
throw Object.assign(new Error(`GraphQL request failed: ${detail}`), { cause: result.left })
Defensive patterns

Strategy: try-catch

Validate before calling

// Ensure auth and URL are valid before running the operation
const probe = await fetch(url, { method: 'POST', headers: { 'content-type': 'application/json', ...authHeaders }, body: JSON.stringify({ query: '{ __typename }' }) })
if (probe.status === 401 || probe.status === 403) throw new Error('Credentials rejected — refresh token/headers before running the operation')

Type guard

function isTransportLeft(left: unknown): left is string | { error: { message: string }; component?: unknown } {
  return typeof left === 'string' || (typeof left === 'object' && left !== null && 'error' in left)
}

Try / catch

try {
  await runTabGQLOperation(tab, options)
} catch (e) {
  const msg = e instanceof Error ? e.message : String(e)
  if (msg === 'cancellation') return
  if (/401|403/i.test(msg)) promptReAuth()
  else showToast('Request failed', msg)
}

Prevention

When it happens

Trigger: Calling runTabGQLOperation when the underlying relay request fails: DNS/connection errors, TLS problems, 401/403/500 responses to the query, CORS/interceptor failures, or cancellation (left === "cancellation").

Common situations: Backend down or URL wrong; expired auth token causing 401 on the query; server crashing with 500 on certain operations; browser interceptor blocked by CORS; user switching tabs cancelling an in-flight operation.

Related errors


AI-assisted analysis of hoppscotch/hoppscotch@ac145e7f75 (2026-09-01). Data as JSON: /api/errors/bf2998e96551228f. Report an issue: GitHub.