Reputation: 5198
I have a django server and a view that is called when the user tries to add himself to a bus.
If the bus is already full, I want to return a HttpResponse with status code "already full" - or something like that, and add a description saying the bus is already full.
again, the server is in django and I am working with django rest framework.
what would you suggest?
Upvotes: 0
Views: 52
Reputation: 856
You should raise a custom exception for full busses
from rest_framework.exceptions import APIException
class FullBusException(APIException):
status_code = 409
default_detail = 'This bus is already full.'
Then in your view code import and raise this exception if the bus is already full when the user tries to add themselves to it. Django rest framework will then deal with handling the exception.
http://www.django-rest-framework.org/api-guide/exceptions/
Upvotes: 1