-
Notifications
You must be signed in to change notification settings - Fork 2
fix(frontend): handle non-JSON error responses in file fetches #285
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
fix(frontend): handle non-JSON error responses in file fetches #285
Conversation
|
I think it's useful to do some defensive programming here, but we should also try to understand why this response is being generated, and change it so that it generates JSON. The Starlette exception handlers should be doing this, and it seems that is not working somehow. |
-inherits from PermissionError -created to distinguish this specific configuration error from other PermissionErrors
- not catching PermissionErrors was what was originally causing no JSON response to be returned from the server when setegid, setgroups, or seteuid failed. Even those these specific errors are not caught by the custom error class and handler, I left in the global PermissionError handler to catch other instances where a PermissionError might not be caught in a specific method
- catch PermissionErrors in EffectiveUserContext.__enter__() and raise the new custom error class instead
|
This frontend fix works for me as expected. I tested it with I opened a PR against this branch to address Konrad's comment. |
The error message was replicated in three places. Doing this means we can set it once but still override it if needed.
…ser-context-error fix: server response for user context error
In reference to the comment, it looks like these two handlers do not catch all exceptions and so would not trigger on all occasions. We could add a general handler like this: This should catch everything and return a JSON response. The question is do we want all our 500 errors to be JSON responses? I think it will be fine, since the current 500 error response is a plain text document with and the new error response would be Neither are very helpful to the user, but the second one does show better error messages when displayed in the application. |
neomorphic
left a comment
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.
The frontend changes look good. There are probably many more cases (~25) where the response.json() should be caught to prevent this issue elsewhere. It looks like there are a number of instances later on in frontend/src/queries/fileQueries.ts that simply return an empty object if the json() method fails.
const body = await response.json().catch(() => ({}));
- ensures JSON is always returned; no plain text
- this allows it's use for more queries
…isplay fix: server error responses and display
@neomorphic With the PR off this branch that addressed your above comment completed and merged, is this PR okay to merge into main now? |
@allison-truhlar, Yeah, it should be fine. |
Fix #283 so that error responses do not result in JSON parsing errors of
that error response being displayed.
Before:

After:
Assisted by Gemini 3 Pro (Low) via Antigravity.