From 3ed2fb5c4c4a8a5e202ced5cbfeaba615907e9f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Luiz=20Santos=20Neto?= Date: Wed, 18 Nov 2026 11:43:10 -0300 Subject: [PATCH] fix(sdk): make 401 and 405 API diagnostics actionable --- langfuse/_utils/parse_error.py | 7 +++++-- tests/unit/test_error_parsing.py | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/langfuse/_utils/parse_error.py b/langfuse/_utils/parse_error.py index e16a4eb71..8d12c21b6 100644 --- a/langfuse/_utils/parse_error.py +++ b/langfuse/_utils/parse_error.py @@ -11,7 +11,9 @@ SUPPORT_URL = "https://langfuse.com/support" API_DOCS_URL = "https://api.reference.langfuse.com" RBAC_DOCS_URL = "https://langfuse.com/docs/rbac" -INSTALLATION_DOCS_URL = "https://langfuse.com/docs/sdk/typescript/guide" +CREDENTIAL_SETUP_URL = ( + "https://langfuse.com/docs/observability/sdk/overview#configure-credentials" +) RATE_LIMITS_URL = "https://langfuse.com/faq/all/api-limits" PYPI_PACKAGE_URL = "https://pypi.org/project/langfuse/" @@ -31,8 +33,9 @@ 504: f"Gateway timeout. {defaultServerErrorPrompt}", 404: f"Internal error occurred. {defaultServerErrorPrompt}", 400: f"Bad request. Please check your request for any missing or incorrect parameters. Refer to our API docs: {API_DOCS_URL} for details.", - 401: f"Unauthorized. Please check your public/private host settings. Refer to our installation and setup guide: {INSTALLATION_DOCS_URL} for details on SDK configuration.", + 401: f"Unauthorized. Check LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY, and LANGFUSE_BASE_URL. See the SDK credential setup guide: {CREDENTIAL_SETUP_URL}", 403: f"Forbidden. Please check your access control settings. Refer to our RBAC docs: {RBAC_DOCS_URL} for details.", + 405: f"Method not allowed. Check LANGFUSE_BASE_URL and whether your server version supports this endpoint. For help, contact support: {SUPPORT_URL}", 429: f"Rate limit exceeded. For more information on rate limits please see: {RATE_LIMITS_URL}", } diff --git a/tests/unit/test_error_parsing.py b/tests/unit/test_error_parsing.py index d71678873..306fbd44a 100644 --- a/tests/unit/test_error_parsing.py +++ b/tests/unit/test_error_parsing.py @@ -19,7 +19,7 @@ def test_generate_error_message_access_denied_error(): def test_generate_error_message_method_not_allowed_error(): exception = MethodNotAllowedError(body={}) - expected_message = "Unexpected error occurred. Please check your request and contact support: https://langfuse.com/support." + expected_message = "Method not allowed. Check LANGFUSE_BASE_URL and whether your server version supports this endpoint. For help, contact support: https://langfuse.com/support" assert generate_error_message_fern(exception) == expected_message @@ -31,7 +31,7 @@ def test_generate_error_message_not_found_error(): def test_generate_error_message_unauthorized_error(): exception = UnauthorizedError(body={}) - expected_message = "Unauthorized. Please check your public/private host settings. Refer to our installation and setup guide: https://langfuse.com/docs/sdk/typescript/guide for details on SDK configuration." + expected_message = "Unauthorized. Check LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY, and LANGFUSE_BASE_URL. See the SDK credential setup guide: https://langfuse.com/docs/observability/sdk/overview#configure-credentials" assert generate_error_message_fern(exception) == expected_message