{"record":{"id":"bbece435eb871773","repo":"mastra-ai/mastra","slug":"stepexecutionerror-res-status-text","errorCode":null,"errorMessage":"StepExecutionError(res.status, text)","messagePattern":"StepExecutionError\\(res\\.status, text\\)","errorType":"http","errorClass":"StepExecutionError","httpStatus":null,"severity":"error","filePath":"packages/core/src/worker/strategies/http-remote-strategy.ts","lineNumber":79,"sourceCode":"    );\n\n    const body = this.#buildBody(params);\n\n    const signal = this.#combineSignals(params.abortSignal);\n\n    const res = await fetch(url, {\n      method: 'POST',\n      headers: {\n        'content-type': 'application/json',\n        ...this.#buildAuthHeaders(),\n      },\n      body,\n      signal,\n    });\n\n    if (!res.ok) {\n      const text = await res.text();\n      throw new StepExecutionError(res.status, text);\n    }\n\n    return res.json() as Promise<StepResult<unknown, unknown, unknown, unknown>>;\n  }\n\n  /**\n   * Build a JSON-serializable request body. The `params.requestContext` is\n   * a plain object; if a caller stuffed a non-serializable value into it we\n   * surface a clear error instead of silently dropping fields.\n   *\n   * `abortSignal` is consumed via fetch's `signal` argument — it must not\n   * be in the body.\n   */\n  #buildBody(params: StepExecutionParams): string {\n    const { abortSignal: _abortSignal, requestContext, ...rest } = params;\n    let safeRequestContext: Record<string, unknown>;\n    try {\n      safeRequestContext = JSON.parse(JSON.stringify(requestContext ?? {}));","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/worker/strategies/http-remote-strategy.ts#L61-L97","documentation":"The HTTP remote worker strategy executes a step by POSTing to a remote endpoint; when the response is not ok it reads the body text and throws StepExecutionError carrying the HTTP status and body. This surfaces remote execution failures (auth, 404, 500, validation) to the worker caller.","triggerScenarios":"Remote step endpoint returns 401/403 (bad auth token), 404 (wrong URL/path), 500 (handler crashed), or 400 (payload rejected by the remote service).","commonSituations":"Expired service-to-service credentials; deployed worker pointing at an outdated or wrong-namespace remote URL; remote handler throwing due to a bug or incompatible step schema after a version upgrade.","solutions":["Read the status and body in StepExecutionError to identify the remote failure and fix the remote handler","Verify the endpoint URL, method, and auth headers used by the strategy config","Check the remote service logs for the corresponding request's stack trace","Add retry with backoff only for transient statuses (502/503/504)"],"exampleFix":"// before\nthrow new StepExecutionError(res.status, text);\n// after (caller side)\ntry {\n  result = await strategy.executeStep(params);\n} catch (e) {\n  if (e instanceof StepExecutionError && e.status >= 500) return retry(params);\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"const url = new URL(endpoint);\nif (url.protocol !== 'https:' && url.protocol !== 'http:') throw new Error('bad endpoint');","typeGuard":"function isStepExecutionError(e: unknown): e is StepExecutionError {\n  return e instanceof StepExecutionError;\n}","tryCatchPattern":"try {\n  result = await strategy.executeStep(params);\n} catch (e) {\n  if (e instanceof StepExecutionError) {\n    if (e.status === 503 || e.status === 502) return retryWithBackoff(params);\n    console.error(`Remote step failed: ${e.status} ${e.body}`);\n  }\n  throw e;\n}","preventionTips":["Monitor the remote endpoint's availability and auth token expiry","Pin endpoint URLs per environment in config","Add retries with backoff only for 5xx statuses","Check remote service logs when statuses appear"],"tags":["network","http","worker","remote-execution"],"backgroundTag":"http-request-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}