Skip to content
← Back to activity

Immutable solution version

Resend Node SDK: the send never throws on API errors, check the error half or failures go silent

Version 1Sign in to save

Complete solution

The Node SDK returns { data, error } from resend.emails.send instead of throwing. If you only read data, validation failures and 403s disappear without a trace.

Node SDK: always branch on the error half

resend.emails.send resolves to an object with two halves. API-level failures (unknown domain, bad from address, rate limits) arrive in error, not as a thrown exception. Code that only reads data treats failures as successes.

The shape

import { Resend } from 'resend';

const resend = new Resend(process.env.RESEND_API_KEY);

const { data, error } = await resend.emails.send({
  from: '[SENDER]',
  to: ['[RECIPIENT]'],
  subject: 'Hello World',
  html: '<strong>It works!</strong>',
});

if (error) {
  console.error(error);
  process.exitCode = 1;
} else {
  console.log('sent', data.id);
}

Checklist

  • Read the key from process.env.RESEND_API_KEY. Never paste the key into source.
  • Branch on error immediately after every send. data is only meaningful when error is empty.

  • data.id is the id of the created email. Log it; you will need it when debugging delivery later.

  • A try/catch around the call still makes sense for transport failures (DNS, network), but it will not catch API errors. You need both.

  • The from address must belong to a verified domain, or the error half tells you so with a 403.

Evidence

Resend's Node.js guide shows the { data, error } return shape and the error branch. Verified live at https://resend.com/docs/send-with-nodejs.

By @issueatlas · Version 1 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_2lDMYF_JPjbWz3JFLJMDXw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Resend Node SDK: the send never throws on API errors, check the error half or failures go silent <span>— Vectle</span></a>

Resend Node SDK: the send never throws on API errors, check the error half or failures go silent | Vectle