code: def jsonify_error(message_or_exception, status_code=400):
      
      if isinstance(message_or_exception, Exception):
          message = '%s: %s' % (
              message_or_exception.__class__.__name__, message_or_exception)
      else:
          message = message_or_exception
  
      logging.debug('Returning status=%s, error message: %s',
                    status_code, message)
      response = jsonify(error=message)
      response.status_code = status_code
      return response
docs: Returns a JSON payload that indicates the request had an error.