question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Debugging errors in the backend

See original GitHub issue

Hello, firstly I want to say thank you because I find this project very useful! I was finding it difficult to debug some errors in a project that I’m working on, so I subclassed the middleware to return errors to the frontend like this:

import traceback

from django.conf import settings
from django.http import HttpResponse


from django_htmx.middleware import HtmxMiddleware


class HtmxDebugMiddleware(HtmxMiddleware):
    def process_exception(self, request, exception):
        if request.htmx and settings.DEBUG:
            content = (
                "<h1>Django HTMX Error</h1><b>%s</b>"
                "<h3>Traceback</h3><textarea rows=10>%s</textarea>"
            ) % (
                exception,
                traceback.format_exc(),
            )

            return HttpResponse(content, status=200)

        return None

Here is an example of what the solution above produces when raise RuntimeError("Something bad happened on the backend!") is encountered:

Screen Shot 2021-07-04 at 2 15 57 am

Would it be desirable to include something similar in this project?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
adamchainzcommented, Jul 8, 2021

Just released in version 1.2.0 - check it out!

0reactions
adamchainzcommented, Jul 8, 2021

Yes, my concern was for the case when debug is not enabled and the script replaces the page with non-debug server error response. The templatetag approach should resolve this by only running this behaviour when debug is enabled.

Ah good, my misunderstanding… I’ve just seen too many people running debug mode in prod 😅

The potential confusion I was alluding to was that in the process of debugging some cases (e.g multiple load triggers) it might seem like the first error was resolved by some change after reloading the page and a different error just happens to return before the previous error is encountered again.

Yes this is true. I’m not sure there’s much we can do about that. Thankfully most pages should be fairly deterministic in the order that errors occur.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Debugging web applications - backend
Debugging web applications - backend ; Input processing errors. HTTP protocol debugging ; Data retrieval errors · SQL query debugging ; Template related...
Read more >
Web API Error Handling: How To Make Debugging Easier
Whether you're the consumer or producer of an API, you've no doubt seen that good error handling can make debugging easier.
Read more >
How to Debug Your Code - Codecademy
Another method of debugging your code is using error handling. Code that does not use error handling will often crash when it encounters...
Read more >
How to debug front-end or back-end issues (must have)?
How to debug front-end or back-end issues (must have)? by Denis Platonov, Co-founder of Test ProStart for free: ...
Read more >
4. Error Handling and Debugging - VBScript in a Nutshell [Book]
Debugging , on the other hand, involves finding errors and removing them from your program. There are many types of errors that you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found