Handle invalid UUID value with django and django-rest-framework

Does anyone know how to manage globally in a django project, an invalid UUID?

If the UUID is invalid, send a 404 or 400 instead of a 500 error.

This UUID error occurs when one or two characters of the uuid are removed from the url.

Example:

raise exceptions.ValidationError(`

`django.core.exceptions.ValidationError: ['La valeur «\xa03114e36b-2935-4302-b74f-33411e9361\xa0» n’est pas un UUID valide.']

I really need to catch and handle this error in my project.