code: def default_error_handler(exception):
      
      http_exception = isinstance(exception, exceptions.HTTPException)
      code = exception.code if http_exception else 500
  
      # log exceptions only (app debug should be off)
      if code == 500:
          current_app.logger.error(exception)
  
      # jsonify error if json requested via accept header
      if has_app_context() and has_request_context():
          headers = request.headers
          if 'Accept' in headers and headers['Accept'] == 'application/json':
              return json_error_handler(exception)
  
      # otherwise render template
      return template_error_handler(exception)
docs: Default error handler
      Will display an error page with the corresponding error code from template
      directory, for example, a not found will load a 404.html etc.
      Will first look in userland app templates and if not found, fallback to
      boiler templates to display a default page.
  
      :param exception: Exception
      :return: string