docs: def api_call(fn):
      """ Returns function result in API format if requested from an API
      endpoint """
  
      @wraps(fn)
      def wrapper(*args, **kwargs):
          try:
              result = fn(*args, **kwargs)
          except (DagobahError, DAGValidationError) as e:
              if request and request.endpoint == fn.__name__:
                  return jsonify(error_type=type(e).__name__, message=e.message), 400
              raise e
          except Exception as e:
              logging.exception(e)
              raise e
  
          if request and request.endpoint == fn.__name__:
              status_code = None
              try:
                  if result and '_status' in result:
                      status_code = result['_status']
                      del result['_status']
              except TypeError:
                  pass
  
              if isinstance(result, dict):
                  if 'result' in result:
                      return jsonify(status=status_code if status_code else 200,
                                     **result)
                  else:
                      return jsonify(status=status_code if status_code else 200,
                                     result=result)
              else:
                  return jsonify(status=status_code if status_code else 200,
                                 result=result)
  
          else:
              return result
  
      return wrapper