Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

722 B
Raw Blame
type StorageErrorShape = {
  name?: unknown;
  code?: unknown;
  Code?: unknown;
  cause?: { code?: unknown };
  $metadata?: { httpStatusCode?: unknown };
  $response?: { statusCode?: unknown };
};

export function describeStorageError(error: unknown) {
  if (typeof error !== "object" || error === null) {
    return { name: typeof error };
  }
  const shape = error as StorageErrorShape;
  const status = shape.$metadata?.httpStatusCode ?? shape.$response?.statusCode;
  const code = shape.Code ?? shape.code ?? shape.cause?.code;
  return {
    name: typeof shape.name === "string" ? shape.name : "Error",
    ...(typeof status === "number" ? { status } : {}),
    ...(typeof code === "string" ? { code } : {}),
  };
}