-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ENH]: GET /databases should return 404 instead of 500 for not found #2788
Conversation
Reviewer ChecklistPlease leverage this checklist to ensure your code review is thorough before approving Testing, Bugs, Errors, Logs, Documentation
System Compatibility
Quality
|
93f5b9b
to
d30bb50
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused by this implementation, the new error is already a ChromaError
so it should be already getting caught by:
except ChromaError as e:
raise e
Why do we need a separate exception path like
except Exception as e:
if isinstance(e, NotFoundError):
...
chromadb/api/async_client.py
Outdated
f"Could not connect to database {database} for tenant {tenant}. Are you sure it exists?" | ||
) | ||
except Exception as e: | ||
if isinstance(e, NotFoundError): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not except NotFoundError
?
it's just except Exception as e:
if isinstance(e, NotFoundError):
raise ValueError(
f"Could not connect to database {database} for tenant {tenant}. Are you sure it exists?"
)
raise e vs. except NotFoundError:
raise ValueError(
f"Could not connect to database {database} for tenant {tenant}. Are you sure it exists?"
)
except Exception as e:
raise e Functionally the same but the second one does look cleaner, so I'll change. |
Discussed offline, class ChromaError(Exception, EnforceOverrides):
trace_id: Optional[str] = None
def code(self) -> int:
"""Return an appropriate HTTP response code for this error"""
return 400 # Bad Request
def message(self) -> str:
return ", ".join(self.args) So let's just use that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description of changes
When a database is not found, a 404 HTTP status code is now returned instead of a 500.
Test plan
How are these changes tested?
Added a new test. It doesn't strictly test the status code (difficult if we want to keep the more friendly error message), but exercises the code path.
Documentation Changes
Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the docs repository?
n/a