Updated Error Handling in api_views.py