from django.urls import path
from django.http import JsonResponse
from polls.views import (RootResource, QuestionCollectionResource,
                         QuestionResource, ChoiceResource)


def healthcheck_view(request):
    return JsonResponse({ 'status': 'ok' }, content_type='application/health+json')


def error_view(request):
    raise Exception('Test exception')


urlpatterns = [
    path('', RootResource.as_view()),
    path('questions', QuestionCollectionResource.as_view()),
    path('questions/<int:pk>', QuestionResource.as_view()),
    path('questions/<int:question_pk>/choices/<int:pk>', ChoiceResource.as_view()),
    path('healthcheck', healthcheck_view),
    path('500', error_view),
]

@@ -1,20 +1,155 @@
+from django.core.exceptions import ImproperlyConfigured%0Afrom django.db import connections%0Afrom django.db.utils import OperationalError%0A
 from django.urls imp
@@ -157,16 +157,16 @@
 rt path%0A
-
 from dja
@@ -361,86 +361,556 @@
     
-return JsonResponse(%7B 'status': 'ok' %7D, content_type='application/health+json'
+content_type = 'application/health+json'%0A    database_accessible = True%0A%0A    try:%0A        connections%5B'default'%5D.cursor()%0A    except ImproperlyConfigured:%0A        # Database is not configured (DATABASE_URL may not be set)%0A        database_accessible = False%0A    except OperationalError:%0A        # Database is not accessible%0A        database_accessible = False%0A%0A    if database_accessible:%0A        return JsonResponse(%7B 'status': 'ok' %7D, content_type=content_type)%0A%0A    return JsonResponse(%7B 'status': 'fail' %7D, status=503, content_type=content_type
 )%0A%0A%0A

make /healthcheck verify database