from flask import render_template
from app.main import main
from dmutils.apiclient import APIError
from dmutils.s3 import S3ResponseError


@main.app_errorhandler(APIError)
def api_error_handler(e):
    return _render_error_page(e.status_code)


@main.app_errorhandler(S3ResponseError)
def s3_response_error_handler(e):
    return _render_error_page(503)


@main.app_errorhandler(404)
def page_not_found(e):
    return _render_error_page(404)


@main.app_errorhandler(500)
def exception(e):
    return _render_error_page(500)


@main.app_errorhandler(503)
def service_unavailable(e):
    return _render_error_page(503)


def _render_error_page(status_code):
    template_map = {
        404: "errors/404.html",
        500: "errors/500.html",
        503: "errors/500.html",
    }
    if status_code not in template_map:
        status_code = 500
    template_data = main.config['BASE_TEMPLATE_DATA']
    return render_template(template_map[status_code], **template_data), status_code

@@ -131,16 +131,73 @@
 seError%0A
+from dmutils.content_loader import QuestionNotFoundError%0A
 %0A%0A@main.
@@ -403,24 +403,144 @@
 page(503)%0A%0A%0A
+@main.app_errorhandler(QuestionNotFoundError)%0Adef content_loader_error_handler(e):%0A    return _render_error_page(400)%0A%0A%0A
 @main.app_er
@@ -824,24 +824,24 @@
 atus_code):%0A
-
     template
@@ -849,16 +849,48 @@
 map = %7B%0A
+        400: %22errors/500.html%22,%0A
         

Handle QuestionNotFoundError