I am using standard error handling in production - if there are server errors I am getting mails. However, on certain APIs I want to have a response with HTTP code 500 or 502 as part of the "valid flow". (It's done for educational purposes)
So my view for that looks like this:
from rest_framework.response import Response
from rest_framework import status
def give_me_error(request):
return Response("This is expected error", status=status.HTTP_500_INTERNAL_SERVER_ERROR)
And what I want is not to get email of this particular response (because I wanted it to be 500)
I've also tried this way:
from django.http import JsonResponse
def give_me_error(request):
return JsonResponse({'error': 'expected error'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
But it also generates mail.
Is there a way to have a view returning error 500 that will not trigger e-mail send? (without disabling the e-mail functionality system-wide)
Per Django documentation: https://docs.djangoproject.com/en/4.0/howto/error-reporting/
When DEBUG is False, Django will email the users listed in the ADMINS setting whenever your code raises an unhandled exception and results in an internal server error (strictly speaking, for any response with an HTTP status code of 500 or greater)