hipo-drf-exceptions icon indicating copy to clipboard operation
hipo-drf-exceptions copied to clipboard

Does not handle 500 errors and messages

Open idiotricks opened this issue 4 years ago • 0 comments

When I add protect to on_delete in one of the FK fields, for example:

class StockIn(Timestamp):
   ....
    supplier = models.ForeignKey(
        Supplier,
        on_delete=models.PROTECT,
        related_name='supplierstockin',
        blank=True,
        null=True
    )

and when I try to delete a supplier, an error 500 occurs. However, the messages are very common such as:

Request failed with status code 500

In fact, I see the error message is (in the form of html not json):

Cannot delete some instances of the 'Supplier' model because they are referenced through a protected foreign key: 'StockIn.supplier'

Can this issue make the message like:

{
     "type": "BlaBlaError",
     "details": {...},
     "fallback_message": "Cannot delete some instances of the 'Supplier' model because they are referenced through a protected foreign key: 'StockIn.supplier'."
}

If it can, this will greatly help us in developing applications quickly and correctly displaying errors to users. Thank you...

idiotricks avatar Mar 27 '20 10:03 idiotricks