Gmail API Error Helpers (src/http.ts)

vercel/chat · packages/adapter-gmail/src/http.ts · typescript · MIT
email, integration, lang:typescript, fw:zod, tag:error-handling

Defines typed errors and validation for Gmail API responses, used when building robust Gmail integrations.

// Source: https://github.com/vercel/chat | License: MIT | Copyright 2026 Vercel, Inc
// Provided via justclaw.it.com; keep this notice with the code.
import { z } from "zod";

export class GmailContentError extends Error {
  readonly reason: "size" | "format";

  constructor(reason: "size" | "format") {
    super(
      reason === "size"
        ? "Gmail content exceeds the size limit"
        : "Gmail MIME content could not be parsed"
    );
    this.name = "GmailContentError";
    this.reason = reason;
  }
}

const reason = z.enum([
  "authError",
  "badRequest",
  "dailyLimitExceeded",
  "domainPolicy",
  "forbidden",
  "rateLimitExceeded",
  "userRateLimitExceeded",
  "backendError",
  "invalid_grant",
  "invalid_client",
  "deleted_client",
]);
const failure = z.object({
  error: z.u

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key