/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v4-mini"; import { remap as remap$ } from "../../lib/primitives.js"; import * as types from "../../types/primitives.js"; import * as models from "../index.js"; import { ModerationAPIError } from "./moderation-api-error.js"; /** * The request is malformed or a parameter is invalid. */ export type BadRequestErrorData = { /** * Broad error category. Stable; safe to switch on. */ type: "invalid_request_error"; /** * Exactly what went wrong. Stable; safe to branch on. New codes may be added. * * @remarks * * - `invalid_request`: A parameter is invalid. `message` says which one. * - `project_id_required`: An organization key called a project endpoint without naming the project in `Project-Id`, and the organization has more than one project. * - `validation_failed`: The request body does not match the schema. `issues` lists each problem with its `path`. */ code: models.BadRequestErrorCode; /** * Human-readable explanation. */ message: string; /** * Validation problems, when the request body is invalid. */ issues?: Array | undefined; /** * Identifies this request. Include it when you contact support. */ requestId: string; /** * Documentation for this `code`. */ docUrl: string; }; /** * The request is malformed or a parameter is invalid. */ export class BadRequestError extends ModerationAPIError { /** * Broad error category. Stable; safe to switch on. */ type: "invalid_request_error"; /** * Exactly what went wrong. Stable; safe to branch on. New codes may be added. * * @remarks * * - `invalid_request`: A parameter is invalid. `message` says which one. * - `project_id_required`: An organization key called a project endpoint without naming the project in `Project-Id`, and the organization has more than one project. * - `validation_failed`: The request body does not match the schema. `issues` lists each problem with its `path`. */ code: models.BadRequestErrorCode; /** * Validation problems, when the request body is invalid. */ issues?: Array | undefined; /** * Identifies this request. Include it when you contact support. */ requestId: string; /** * Documentation for this `code`. */ docUrl: string; /** The original data that was passed to this error instance. */ data$: BadRequestErrorData; constructor( err: BadRequestErrorData, httpMeta: { response: Response; request: Request; body: string }, ) { const message = err.message || `API error occurred: ${JSON.stringify(err)}`; super(message, httpMeta); this.data$ = err; this.type = err.type; this.code = err.code; if (err.issues != null) this.issues = err.issues; this.requestId = err.requestId; this.docUrl = err.docUrl; this.name = "BadRequestError"; } } /** @internal */ export const BadRequestError$inboundSchema: z.ZodMiniType< BadRequestError, unknown > = z.pipe( z.object({ type: types.literal("invalid_request_error"), code: models.BadRequestErrorCode$inboundSchema, message: types.string(), issues: types.optional(z.array(models.ErrorIssue$inboundSchema)), request_id: types.string(), doc_url: types.string(), request$: z.custom(x => x instanceof Request), response$: z.custom(x => x instanceof Response), body$: z.string(), }), z.transform((v) => { const remapped = remap$(v, { "request_id": "requestId", "doc_url": "docUrl", }); return new BadRequestError(remapped, { request: v.request$, response: v.response$, body: v.body$, }); }), );