UNPKG

neverbounce

Version:

An API wrapper for the NeverBounce API

77 lines (76 loc) 3.25 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const NeverBounce_js_1 = __importDefault(require("../src/NeverBounce.js")); const Errors_js_1 = __importDefault(require("../src/Errors.js")); // Initialize NeverBounce client // api key has been intentionally left out to trigger an error const client = new NeverBounce_js_1.default({}); // Verify an email client.single.check('mike@neverbounce.com', true, true) .then((result) => console.log('[THEN]', result)) .catch((err) => { switch (err.type) { case NeverBounce_js_1.default.errors.AuthError: // The API credentials used are bad, have you reset them recently? console.log('[THEN]', err.message); break; case NeverBounce_js_1.default.errors.BadReferrerError: // The script is being used from an unauthorized source, you may need to // adjust your app's settings to allow it to be used from here console.log('[THEN]', err.message); break; case NeverBounce_js_1.default.errors.ThrottleError: // Too many requests in a short amount of time, try again shortly or adjust // your rate limit settings for this application in the dashboard console.log('[THEN]', err.message); break; case NeverBounce_js_1.default.errors.GeneralError: // A non recoverable API error occurred check the message for details console.log('[THEN]', err.message); break; default: // Other non specific errors console.log('[THEN]', err); break; } }); // Alternative using async/await async function checkEmailWithErrorHandling() { try { // This will fail due to missing API key const result = await client.single.check('mike@neverbounce.com', true, true); console.log('[ASYNC]', result); } catch (err) { if (err instanceof Errors_js_1.default) { switch (err.type) { case NeverBounce_js_1.default.errors.AuthError: console.log('[ASYNC] Auth Error:', err.message); break; case NeverBounce_js_1.default.errors.BadReferrerError: console.log('[ASYNC] Bad Referrer Error:', err.message); break; case NeverBounce_js_1.default.errors.ThrottleError: console.log('[ASYNC] Throttle Error:', err.message); break; case NeverBounce_js_1.default.errors.GeneralError: console.log('[ASYNC] General Error:', err.message); break; default: console.log('[ASYNC] Unknown Error Type:', err.message); break; } } else if (err instanceof Error) { console.log('[ASYNC] Standard Error:', err.message); } else { console.log('[ASYNC] Unknown Error:', err); } } } // Run the async version checkEmailWithErrorHandling();