{"record":{"id":"5949034f278d7db5","repo":"supermemoryai/supermemory","slug":"supermemory-api-request-failed-error","errorCode":null,"errorMessage":"Supermemory API request failed: ${error}","messagePattern":"Supermemory API request failed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/tools/src/openai/middleware.ts","lineNumber":131,"sourceCode":"\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\tAuthorization: `Bearer ${apiKey}`,\n\t\t\t},\n\t\t\tbody: payload,\n\t\t})\n\n\t\tif (!response.ok) {\n\t\t\tconst errorText = await response.text().catch(() => \"Unknown error\")\n\t\t\tthrow new Error(\n\t\t\t\t`Supermemory profile search failed: ${response.status} ${response.statusText}. ${errorText}`,\n\t\t\t)\n\t\t}\n\n\t\treturn await response.json()\n\t} catch (error) {\n\t\tif (error instanceof Error) {\n\t\t\tthrow error\n\t\t}\n\t\tthrow new Error(`Supermemory API request failed: ${error}`)\n\t}\n}\n\n/**\n * Adds memory-enhanced system prompts to chat completion messages.\n *\n * Searches for relevant memories based on the specified mode and injects them\n * into the conversation. If a system prompt already exists, memories are appended\n * to it. Otherwise, a new system prompt is created with the memories.\n *\n * @param messages - Array of chat completion message parameters\n * @param containerTag - The container tag/identifier for memory search\n * @param logger - Logger instance for debugging and info output\n * @param mode - Memory search mode: \"profile\" (all memories), \"query\" (search-based), or \"full\" (both)\n * @param baseUrl - The Supermemory API base URL\n * @param apiKey - The Supermemory API key used to authenticate the request\n * @returns Promise that resolves to enhanced messages with memory-injected system prompt\n *","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/supermemoryai/supermemory/blob/d436792e777a99865939dd543c8d1a16d57f54ec/packages/tools/src/openai/middleware.ts#L113-L149","documentation":"A catch-all in supermemoryProfileSearch that re-throws non-Error throwables (strings, plain objects, DOMExceptions from AbortSignal timeouts) wrapped as Error so callers always get an Error with a stack. The original value is preserved in the message.","triggerScenarios":"fetch rejecting with an AbortError/timeout DOMException that is not an Error instance in the runtime, or custom fetch implementations rejecting with plain objects.","commonSituations":"Request aborted via AbortSignal.timeout (FETCH_TIMEOUT_MS) in edge/serverless runtimes; quirky fetch polyfills rejecting with strings.","solutions":["Inspect the wrapped message to find the real rejection cause","Handle abort/timeout cases explicitly and retry or degrade","Upgrade the runtime/polyfill so fetch rejections are standard Errors"],"exampleFix":"// before\nawait supermemoryProfileSearch(payload)\n\n// after\ntry {\n  await supermemoryProfileSearch(payload)\n} catch (e) {\n  if (e instanceof Error && /abort/i.test(e.message)) return fallback()\n  throw e\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await supermemoryProfileSearch(p) } catch (e) { if (e instanceof Error && /abort|timeout/i.test(e.message)) return fallback; throw e }","preventionTips":["Set explicit AbortSignals and handle aborts as a distinct case","Log the wrapped message verbatim to preserve the original rejection cause"],"tags":["fetch","timeout","abort","supermemory"],"backgroundTag":"non-error-rejection","analyzedSha":"d436792e777a99865939dd543c8d1a16d57f54ec","analyzedAt":"2026-08-28T18:04:46.947Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}