Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

592 B
Raw Blame
export function logAndRespond(
  body: string | Record<string, unknown>,
  {
    status = 200,
    logLevel = "info",
  }: {
    status?: number;
    logLevel?: "error" | "warn" | "info";
  } = {},
) {
  // When string
  if (typeof body === "string") {
    console[logLevel](body);
    return new Response(body, { status });
  }

  // When object
  console[logLevel](body);
  return new Response(JSON.stringify(body), {
    status,
    headers: {
      "Content-Type": "application/json",
    },
  });
}

export function logAndReturn<T>(value: T): T {
  console.log(value);
  return value;
}