code: def route(func):
      async def wrapper(
          endpoint: HTTPEndpoint, request: Request, *args
      ) -> t.Union[dict, Response]:
          try:
              body = await request.body()
              payload = body.decode("utf-8")
              data = json_util.loads(payload) if payload else {}
              response = await func(endpoint, request, data, *args)
              if isinstance(response, Response):
                  return response
  
              return Response(
                  await run_sync_task(lambda: json_util.dumps(response))
              )
          except Exception as e:
              logging.exception(e)
              return JSONResponse(
                  {
                      "kind": "Server Error",
                      "stack": traceback.format_exc(),
                  },
                  status_code=500,
              )
  
      return wrapper
  
file_path: fiftyone/fiftyone/server/decorators.py
imports: import traceback
  import typing
  import logging
  from bson import json_util
  from fiftyone.core.utils import run_sync_task
  from starlette.endpoints import HTTPEndpoint
  from starlette.responses import JSONResponse, Response
  from starlette.requests import Request
label_desc: Use image node_id 1 for calling a global function with example usage: route(func) and returns: wrapper, Response, response, JSONResponse