@solufy/evolution-sdk
Version:
Unofficial SDK for the Evolution Whatsapp API v2
64 lines • 1.63 kB
JavaScript
// src/api/errors.ts
import { z } from "zod";
var EvolutionApiError = class _EvolutionApiError extends Error {
constructor(message, cause) {
const error = getErrorMessage(cause);
super(message, error ? void 0 : { cause });
this.name = _EvolutionApiError.name;
this.message = error ?? message;
}
};
var ErrorMessages = [
ErrorMessage(
z.object({
message: z.array(
z.object({
exists: z.literal(false),
jid: z.string(),
number: z.string()
})
)
}),
"Provided number is not a valid WhatsApp number"
),
ErrorMessage(
z.object({
message: z.array(z.string().includes("Media upload failed on all hosts"))
}),
"Media upload failed on all hosts"
),
ErrorMessage(
z.object({
message: z.array(z.string().includes("AxiosError"))
}),
(response) => response.message[0]
),
ErrorMessage(
z.object({
message: z.array(z.string().includes("No session"))
}),
"No session found, try restarting your instance"
),
ErrorMessage(
z.object({
message: z.array(z.string().includes("AggregateError"))
}),
"AggregateError"
)
];
function getErrorMessage(response) {
const error = ErrorMessages.find(
(message) => message.schema.safeParse(response).success
);
return error ? typeof error.message === "string" ? error.message : (
// biome-ignore lint/suspicious/noExplicitAny: Generic
error.message(response)
) : void 0;
}
function ErrorMessage(schema, message) {
return { schema, message };
}
export {
EvolutionApiError
};
//# sourceMappingURL=errors.mjs.map