From dd7e28fae6bedd711f381e25a32780750cdb7949 Mon Sep 17 00:00:00 2001 From: cthomas Date: Wed, 28 Jan 2026 11:34:29 -0800 Subject: [PATCH] fix: return 400 instead of 500 for image fetch errors (#9157) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Problem:** When a user sends a message with an image URL that times out or fails to fetch, the server returns a 500 Internal Server Error with a generic message. This is confusing because the user doesn't know what went wrong. **Root Cause:** `LettaImageFetchError` was not registered in the exception handlers, so it bubbled up as an unhandled exception. **Fix:** Register `LettaImageFetchError` with the 400 Bad Request handler. Now users get a clear error message like: ``` Failed to fetch image from https://...: Timeout after 2 attempts ``` This tells users exactly what went wrong so they can retry with a different image or verify the URL is accessible. 👾 Generated with [Letta Code](https://letta.com) Co-authored-by: Letta --- letta/server/rest_api/app.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/letta/server/rest_api/app.py b/letta/server/rest_api/app.py index bd2fda02..fa523f5e 100644 --- a/letta/server/rest_api/app.py +++ b/letta/server/rest_api/app.py @@ -38,6 +38,7 @@ from letta.errors import ( HandleNotFoundError, LettaAgentNotFoundError, LettaExpiredError, + LettaImageFetchError, LettaInvalidArgumentError, LettaInvalidMCPSchemaError, LettaMCPConnectionError, @@ -477,6 +478,7 @@ def create_application() -> "FastAPI": app.add_exception_handler(LettaToolNameConflictError, _error_handler_400) app.add_exception_handler(AgentFileImportError, _error_handler_400) app.add_exception_handler(EmbeddingConfigRequiredError, _error_handler_400) + app.add_exception_handler(LettaImageFetchError, _error_handler_400) app.add_exception_handler(ValueError, _error_handler_400) # 404 Not Found errors