// This file was auto-generated by Fern from our API Definition.

import type * as core from "../core/index.js";
import * as errors from "./index.js";

export function handleNonStatusCodeError(
    error: core.Fetcher.Error,
    rawResponse: core.RawResponse,
    method: string,
    path: string,
): never {
    switch (error.reason) {
        case "non-json":
            throw new errors.VapiError({
                statusCode: error.statusCode,
                body: error.rawBody,
                rawResponse: rawResponse,
            });
        case "body-is-null":
            throw new errors.VapiError({
                statusCode: error.statusCode,
                rawResponse: rawResponse,
            });
        case "timeout":
            throw new errors.VapiTimeoutError(`Timeout exceeded when calling ${method} ${path}.`, {
                cause: error.cause,
            });
        case "unknown":
            throw new errors.VapiError({
                message: error.errorMessage,
                rawResponse: rawResponse,
                cause: error.cause,
            });
        default:
            throw new errors.VapiError({
                message: "Unknown error",
                rawResponse: rawResponse,
            });
    }
}
