// 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.LatitudeApiError({
                statusCode: error.statusCode,
                body: error.rawBody,
                rawResponse: rawResponse,
            });
        case "body-is-null":
            throw new errors.LatitudeApiError({
                statusCode: error.statusCode,
                rawResponse: rawResponse,
            });
        case "timeout":
            throw new errors.LatitudeApiTimeoutError(`Timeout exceeded when calling ${method} ${path}.`, {
                cause: error.cause,
            });
        case "unknown":
            throw new errors.LatitudeApiError({
                message: error.errorMessage,
                rawResponse: rawResponse,
                cause: error.cause,
            });
        default:
            throw new errors.LatitudeApiError({
                message: "Unknown error",
                rawResponse: rawResponse,
            });
    }
}
