Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • Django Template Django Template
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 11
    • Issues 11
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 1
    • Merge requests 1
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • IzeniIzeni
  • Django TemplateDjango Template
  • Wiki
  • exception handling tips

exception handling tips · Changes

Page history
Create exception handling tips authored Oct 31, 2024 by Jordan Price's avatar Jordan Price
Hide whitespace changes
Inline Side-by-side
exception-handling-tips.md 0 → 100644
View page @ 977519e2
Django REST Framework has a few quirks that aren't immediately obvious that can make handling errors from a frontend challenging if certain rules are not followed. Following these rules when raising exceptions in DRF views and serializers allow the frontend to handle error responses easily and in a consistent manner.
Before continuing, please read the [Exceptions](https://www.django-rest-framework.org/api-guide/exceptions/) API Guide page on DRF's site.
## Serializers and views must only raise subclasses of `rest_framework.exceptions.APIException`
### Special case of PermissionDenied and Http404
### Non DRF exceptions
## Always raise an exception, never manually return a `Response` with an error status code
## `ValidationError` must only be raised in the `validate` or `validate_<field>` methods of a serializer
## Messages will be displayed to the user!
\ No newline at end of file
Clone repository
  • exception handling tips
  • recommended development tools
  • stripe integration