Skip to content

More helpful errors in logs / terminal #7645

@tim-mccurrach

Description

@tim-mccurrach

Checklist

  • I have verified that that issue exists against the master branch of Django REST framework.
  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • This is not a usage question.
  • This cannot be dealt with as a third party library.
  • I have reduced the issue to the simplest possible case.
  • I have included a failing passing test as a pull request.

Steps to reproduce

Useful information from Exceptions that could helpfully be logged is often not:

class SomeView(APIView):

	def get(self,request):
		raise ValidationError("Some useful message")

Expected Hoped for behavior

# In the terminal / logs
Bad Request (Some useful message): /some/url/ 

# Or if the exception details aren't a single string
Bad Request (See response body for details): /some/url/

Actual behavior

# In the terminal / logs
Bad Request: /some/url/ 

The terminal is probably the first place I look when something isn't working, and the above doesn't leave much of a starting point for investigation. In my case it turned out to just be a ValidationError, but I didn't think of checking the response body (where the error details were returned) until quite a bit of time spent debugging (and not getting anywhere). It would be useful to have slightly more info than just the status code (especially for people new to DRF!).

The logging above actually happens in django, not DRF, however django provides means to customise the message. (see PR)

This will:

  • make it easy to distinguish between ValidationErrors and ParserErrors, (which are both 400s) and between AuthenticationFailed and NotAuthenticated errors (which are both 401s).
  • In cases where the error details are too much to display simply, at least point anyone reading the error in the right direction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions