@solufy/evolution-sdk
Version:
Unofficial SDK for the Evolution Whatsapp API v2
88 lines (87 loc) • 2.85 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/api/errors.ts
var errors_exports = {};
__export(errors_exports, {
EvolutionApiError: () => EvolutionApiError
});
module.exports = __toCommonJS(errors_exports);
var import_zod = require("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(
import_zod.z.object({
message: import_zod.z.array(
import_zod.z.object({
exists: import_zod.z.literal(false),
jid: import_zod.z.string(),
number: import_zod.z.string()
})
)
}),
"Provided number is not a valid WhatsApp number"
),
ErrorMessage(
import_zod.z.object({
message: import_zod.z.array(import_zod.z.string().includes("Media upload failed on all hosts"))
}),
"Media upload failed on all hosts"
),
ErrorMessage(
import_zod.z.object({
message: import_zod.z.array(import_zod.z.string().includes("AxiosError"))
}),
(response) => response.message[0]
),
ErrorMessage(
import_zod.z.object({
message: import_zod.z.array(import_zod.z.string().includes("No session"))
}),
"No session found, try restarting your instance"
),
ErrorMessage(
import_zod.z.object({
message: import_zod.z.array(import_zod.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 };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
EvolutionApiError
});
//# sourceMappingURL=errors.js.map