n8n-nodes-emailverify
Version:
n8n node to verify emails using EmailVerify.io
40 lines (39 loc) • 1.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.emailVerifyIoApiRequest = void 0;
async function emailVerifyIoApiRequest(method, endpoint, body = {}, qs = {}) {
const credentials = await this.getCredentials('emailVerifyApi');
const options = {
method,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
uri: `https://app.emailverify.io/api/v1${endpoint}`,
body,
qs: {
...qs,
key: credentials.apiKey,
},
json: true,
};
if (Object.keys(body).length === 0) {
delete options.body;
}
try {
return await this.helpers.request(options);
}
catch (error) {
if (error.statusCode === 401) {
throw new Error('Invalid EmailVerify.io API key');
}
if (error.statusCode === 429) {
throw new Error('Rate limit exceeded');
}
if (error.statusCode === 403) {
throw new Error('Insufficient credits in your EmailVerify.io account');
}
throw error;
}
}
exports.emailVerifyIoApiRequest = emailVerifyIoApiRequest;