exception handler¶
این صفحه از docstringهای خود کد ساخته میشود، که به انگلیسیاند.
handlers
¶
The exception handler: every failure a DRF view raises, answered in the envelope.
REST_FRAMEWORK = {'EXCEPTION_HANDLER': 'drf_parcel.handlers.exception_handler'}
What it recognises, in order:
- Django's own
Http404,PermissionDeniedandValidationError, turned into DRF's. - A validation error - the first problem in
message, every problem indata.fields, each with its code and a flat path. - Any
APIException- DRF's, the library's, a project's own: its status, its code aserror_code, its detail asmessage, itsdata. DRF's own handler runs first, so the headers it adds -Retry-After,WWW-Authenticate- stay on the answer. - An
IntegrityError, whenHANDLE_INTEGRITY_ERRORSis on: a unique or foreign-key constraint is a 409; every other is a bug. - Anything else - a bug. A generic 500 whose text never leaves the server,
logged with its traceback and reported. Under
DEBUGit is raised instead, so Django's page shows it.
Every 5xx answered - a designed one too - is logged and reported, and every failure answered marks the request's transaction for rollback.
exception_handler
¶
Turn anything a DRF view raised into the envelope - or, under DEBUG, let a bug through.