from flask import jsonify, current_app

from . import status
from . import utils
from ..main.services.search_service import status_for_all_indexes


@status.route('/_status')
def status():

    db_status = status_for_all_indexes()

    if db_status['status_code'] == 200:
        return jsonify(
            status="ok",
            version=utils.get_version_label(),
            db_status=db_status
        )

    current_app.logger.exception("Error connecting to elasticsearch")

    return jsonify(
        status="error",
        version=utils.get_version_label(),
        message="Error connecting to elasticsearch",
        db_status=db_status
    ), 500

@@ -629,33 +629,114 @@
   db_status=
-db_status
+%7B%0A            'status_code': 500,%0A            'message': db_status%5B'message'%5D%5B0%5D%0A        %7D
 %0A    ), 500%0A

Return correct message if elasticsearch fails to connect.