{"record":{"id":"405be56116b11d48","repo":"lfnovo/open-notebook","slug":"credential-not-found","errorCode":null,"errorMessage":"Credential not found","messagePattern":"Credential not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"api/routers/credentials.py","lineNumber":223,"sourceCode":"    except Exception as e:\n        logger.error(f\"Error creating credential: {e}\")\n        raise HTTPException(status_code=500, detail=\"Failed to create credential\")\n\n\n@router.get(\"/{credential_id}\", response_model=CredentialResponse)\nasync def get_credential(credential_id: str):\n    \"\"\"Get a specific credential by ID. Never returns api_key.\"\"\"\n    try:\n        cred = await Credential.get(credential_id)\n        models = await cred.get_linked_models()\n        return credential_to_response(cred, len(models))\n    except HTTPException:\n        raise\n    except OpenNotebookError:\n        raise\n    except Exception as e:\n        logger.error(f\"Error fetching credential {credential_id}: {e}\")\n        raise HTTPException(status_code=404, detail=\"Credential not found\")\n\n\n@router.put(\"/{credential_id}\", response_model=CredentialResponse)\nasync def update_credential(credential_id: str, request: UpdateCredentialRequest):\n    \"\"\"Update an existing credential.\"\"\"\n    try:\n        require_encryption_key()\n    except ValueError as e:\n        raise _handle_value_error(e)\n\n    # Validate all URL fields being updated\n    for url_field in [\n        request.base_url, request.endpoint, request.endpoint_llm,\n        request.endpoint_embedding, request.endpoint_stt, request.endpoint_tts,\n    ]:\n        if url_field:\n            try:\n                await validate_url(url_field, \"update\")","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/lfnovo/open-notebook/blob/a7de90d38aaf18ee85fd661854d35c11e44613e2/api/routers/credentials.py#L205-L241","documentation":"404 returned by GET /api/credentials/{credential_id}. Note this handler catches ALL non-HTTP, non-OpenNotebook exceptions as 404 — so it means either the credential genuinely does not exist, or a lookup blew up unexpectedly.","triggerScenarios":"Fetching a credential with a stale/wrong ID (e.g. after it was deleted or after a DB reset wiped records), or an unexpected exception during fetch that the blanket handler maps to 404.","commonSituations":"Frontend holding a cached credential ID from a previous session, DB reinitialized without preserving records, or ID typo/manipulation in the URL.","solutions":["Verify the ID exists by listing credentials (GET /api/credentials) and copying the exact id","If records vanished, check whether the database was reset or pointed at a different namespace/database in config","Check logs for 'Error fetching credential <id>: ...' — an exception there means the 404 is masking a real error","Refresh the client's cached credential list before retrying"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const creds = await api.listCredentials();\nconst exists = creds.some(c => c.id === credentialId);\nif (!exists) refreshCredentialList();","typeGuard":null,"tryCatchPattern":"try {\n  const cred = await api.getCredential(credentialId);\n} catch (e) {\n  if (e.status === 404) { removeFromLocalCache(credentialId); showNotFound(); return; }\n  throw e;\n}","preventionTips":["Always list-then-navigate instead of trusting cached IDs","Evict 404'd IDs from client caches immediately"],"tags":["credentials","not-found","http-404"],"backgroundTag":"resource-not-found","analyzedSha":"a7de90d38aaf18ee85fd661854d35c11e44613e2","analyzedAt":"2026-08-27T02:39:58.166Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}