{"record":{"id":"ddbcad04bfe813e5","repo":"mem0ai/mem0","slug":"error-as-error-message","errorCode":null,"errorMessage":"(error as Error).message","messagePattern":"\\(error as Error\\)\\.message","errorType":"exception","errorClass":"NodeApiError","httpStatus":null,"severity":"warning","filePath":"integrations/n8n-nodes-mem0/nodes/Mem0/Mem0.node.ts","lineNumber":569,"sourceCode":"\t\t\t\t\t\t\titemIndex: i,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tresponseData = await request('PUT', `/v1/memories/${encodeURIComponent(memoryId)}/`, body);\n\t\t\t\t} else if (operation === 'delete') {\n\t\t\t\t\tconst memoryId = this.getNodeParameter('memoryId', i) as string;\n\t\t\t\t\tresponseData = await request('DELETE', `/v1/memories/${encodeURIComponent(memoryId)}/`);\n\t\t\t\t}\n\n\t\t\t\tconst arr = Array.isArray(responseData) ? responseData : [responseData];\n\t\t\t\tfor (const entry of arr) {\n\t\t\t\t\treturnData.push({ json: entry, pairedItem: { item: i } });\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\treturnData.push({ json: { error: (error as Error).message }, pairedItem: { item: i } });\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tthrow new NodeApiError(this.getNode(), error as JsonObject, { itemIndex: i });\n\t\t\t}\n\t\t}\n\n\t\treturn [returnData];\n\t}\n}\n\nfunction buildEntityFilters(\n\tids: Record<string, string>,\n\tctx: IExecuteFunctions,\n\titemIndex: number,\n): IDataObject {\n\tconst clauses: IDataObject[] = Object.entries(ids)\n\t\t.filter(([, value]) => value)\n\t\t.map(([key, value]) => ({ [key]: value }));\n\n\tif (clauses.length === 0) {\n\t\tthrow new NodeOperationError(","sourceCodeStart":551,"sourceCodeEnd":587,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/integrations/n8n-nodes-mem0/nodes/Mem0/Mem0.node.ts#L551-L587","documentation":"DELETE /api-keys/{key_id} returns 404 when the UUID parses but either no APIKey row with that id exists, or the key exists but was created by a different user (created_by != user.id). Ownership enforcement prevents users from revoking each other's keys, and both cases share one message to avoid enumeration.","triggerScenarios":"Deleting a key created by another account while authenticated as yourself; deleting a key from a different environment/database; deleting a key whose row was already removed; using an admin-created key id while logged in as a member.","commonSituations":"Shared staging server where several accounts create keys and teammates copy ids between scripts; DB reset making all previously listed key ids stale; logging in with a different account than the one that owns the automation keys.","solutions":["List your own keys with GET /api-keys and delete by its id while authenticated as the same user that created it.","If admin management is needed, authenticate with ADMIN_API_KEY or an admin account appropriate to your deployment's policy.","After a database reset, regenerate keys — old ids no longer resolve."],"exampleFix":"# before\nrequests.delete(f\"{BASE}/api-keys/{other_users_key_id}\", headers=my_token)  # 404\n\n# after\nmine = requests.get(f\"{BASE}/api-keys\", headers=my_token).json()\nrequests.delete(f\"{BASE}/api-keys/{mine[0]['id']}\", headers=my_token)","handlingStrategy":"validation","validationCode":"keys = requests.get(f\"{BASE}/api-keys\", headers=my_headers).json()\nowned = {k[\"id\"] for k in keys}  # listing returns only keys visible to you\nif key_id not in owned:\n    raise LookupError(f\"{key_id} is not one of your API keys; cannot revoke\")","typeGuard":"def owned_key_ids(keys_response: list[dict]) -> set[str]:\n    return {k[\"id\"] for k in keys_response if isinstance(k.get(\"id\"), str)}","tryCatchPattern":"if resp.status_code == 404:\n    # missing OR not yours — either way, resync from GET /api-keys instead of retrying\n    keys = requests.get(f\"{BASE}/api-keys\", headers=my_headers).json()","preventionTips":["Always revoke keys while authenticated as their creator.","Resync key lists after environment or DB changes.","Tag keys with labels identifying owner and purpose."],"tags":["api-key","http-404","ownership","rest-server"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}