Skip to content

Commit

Permalink
feat: adds 404 urls
Browse files Browse the repository at this point in the history
  • Loading branch information
yokwejuste committed Aug 19, 2024
1 parent 7f17b6a commit 049f8ab
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
17 changes: 17 additions & 0 deletions apps/users/views/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,20 @@ def index(request):
"message": "Looks like we are up and running!",
}
return JsonResponse(data)

def page_not_found_view(request, exception=None):
return JsonResponse({
'status_code': 404,
'errors': [
'The resource was not found'
]
})


def server_error_view(request):
return JsonResponse({
'status_code': 500,
'errors': [
'An error occurred while processing your request',
]
})
3 changes: 3 additions & 0 deletions website_api/routes/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
)

handler404 = "apps.users.views.index.page_not_found_view"
handler500 = "apps.users.views.index.server_error_view"
5 changes: 2 additions & 3 deletions website_api/routes/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
urlpatterns = [
path('api/schema/', SpectacularAPIView.as_view(), name='schema'),
re_path(r'^$', TemplateView.as_view(template_name='docs/redoc.html'), name='index'),
# re_path(r'$swagger/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),
# re_path(r'$', SpectacularRedocView.as_view(url_name='schema'), name='redoc'),
re_path(r'$swagger/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),
]
elif settings.ENVIRONMENT == "production":
urlpatterns = [
path('', index, name='index'),
path('api/schema/', SpectacularAPIView.as_view(), name='schema'),
path('swagger/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),
path('redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'),
path('redoc/', TemplateView.as_view(template_name='docs/redoc.html'), name='index'),
]

0 comments on commit 049f8ab

Please sign in to comment.