Skip to content
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

Improve formatting of back-end exceptions #3343

Open
maxpatiiuk opened this issue Apr 14, 2023 · 7 comments
Open

Improve formatting of back-end exceptions #3343

maxpatiiuk opened this issue Apr 14, 2023 · 7 comments
Assignees
Labels
1 - Bug Incorrect behavior of the product

Comments

@maxpatiiuk
Copy link
Member

Screenshot 2023-04-07 at 15 53 01

Back-end sends a stack trace properly formatted, but front-end glues all lines into one big mess. Need to wrap it in <pre></pre> to fix this. Better yet, @melton-jason is there a way to get back the original django exception page (when in development) - it was quite helpful

See #3315 (review) for another example

@maxpatiiuk maxpatiiuk added the 1 - Bug Incorrect behavior of the product label Apr 14, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Front-End Backlog Apr 14, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Back-End Backlog Apr 14, 2023
@melton-jason
Copy link
Contributor

I believe this issue was not always the case. Some update (maybe the Django/Python update) or change in the code caused this problem.
Even now there are times when I come across the original Django error messages in Debug mode, but I am unsure exactly what causes it.

I have done some looking into this before:

The middleware is properly returning nothing (None) when Debug mode is enabled

if not settings.DEBUG:

So Django is sending its own error message to the frontend

Perhaps changing the order in which Django handles the middleware will alleviate the problem (See the Django docs on Middleware layering) or maybe Django has since migrated the error message into another Middleware option (here is a list of all available Middleware)

Currently, our Middleware is layered as:

MIDDLEWARE = [
# 'middleware.profilemiddleware.ProfileMiddleware',
'django.middleware.gzip.GZipMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'specifyweb.context.middleware.ContextMiddleware',
'specifyweb.permissions.middleware.PermissionsMiddleware',
'specifyweb.middleware.general.GeneralMiddleware',
]

I will do some further investigation so we can get back to the Django responses!

@melton-jason
Copy link
Contributor

melton-jason commented May 17, 2023

I have done further investigation into this issue and here is what I have found so far:

  • This issue is not caused by the middleware introduced in Improve error response from backend #2702
    • Completely removing the middleware and rebuilding the backend containers still exhibits the same behavior
  • Templated views (like the 404 Page Not Found view) still appear as normal, without the weird formatting.

django_template

I think that Django is not sending proper HTML to the frontend, and rather sending formatted text (with tabs and new lines). I am unsure why Django is doing this suddenly, and have had little luck thus far finding similar experiences online.

@maxpatiiuk
Copy link
Member Author

Could it be because front-end uses Accept: text/plain header when it calls ajax?

@melton-jason
Copy link
Contributor

melton-jason commented May 17, 2023

Yes, I'd say that's worth investigating! I will try and take a look and see if that is the issue soon.

@grantfitzsimmons
Copy link
Member

@melton-jason Take a look at this issue when you get a chance (no rush).

@melton-jason
Copy link
Contributor

Could it be because front-end uses Accept: text/plain header when it calls ajax?

Yes, this seems to be the issue.
I did a quick testing of this by changing the Accept header of backbone ajax to be text/html, and the error message was once again properly displayed/formatted.

Accept: request.type === 'DELETE' ? 'text/plain' : 'application/json',

@emenslin
Copy link
Collaborator

emenslin commented Aug 5, 2024

Can recreate in edge (7.9.6)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 - Bug Incorrect behavior of the product
Projects
Status: 📋 Backlog
Status: 📋 Backlog
Development

No branches or pull requests

4 participants