{"record":{"id":"ef596f608eb529a0","repo":"kriasoft/react-starter-kit","slug":"resend-api-error-result-error-message-result","errorCode":null,"errorMessage":"Resend API error: ${result.error.message || result.error.name || \"Unknown error\"}","messagePattern":"Resend API error: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/api/lib/email.ts","lineNumber":65,"sourceCode":"  if (!env.RESEND_EMAIL_FROM) {\n    throw new Error(\"RESEND_EMAIL_FROM environment variable is required\");\n  }\n\n  // A fresh client per send: the Workers runtime reuses an isolate across\n  // requests, and a module-level client would outlive the env it was built from.\n  const resend = new Resend(env.RESEND_API_KEY);\n\n  try {\n    const result = await resend.emails.send({\n      from: options.from || env.RESEND_EMAIL_FROM,\n      to: options.to,\n      subject: options.subject,\n      html: options.html,\n      text: options.text,\n    });\n\n    if (result.error) {\n      throw new Error(\n        `Resend API error: ${result.error.message || result.error.name || \"Unknown error\"}`,\n      );\n    }\n\n    return result;\n  } catch (error) {\n    throw new Error(\n      `Failed to send email: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n      { cause: error },\n    );\n  }\n}\n\n/**\n * Send email verification message.\n *\n * @param env Environment variables\n * @param options User and verification URL (should be time-limited, signed token)","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/kriasoft/react-starter-kit/blob/0aa7603435f16159ad0b8fef68fb7f6280be7ca1/apps/api/lib/email.ts#L47-L83","documentation":"Resend's SDK does not throw on API failures; it returns { data, error }. sendEmail checks result.error after resend.emails.send() and converts it into a thrown Error whose message is Resend's own error message or name. This is the provider rejecting the request after the request reached Resend (or the SDK failed to build it).","triggerScenarios":"Calling sendEmail (via sendVerificationEmail, sendPasswordReset, sendOTP) when Resend rejects: invalid/revoked RESEND_API_KEY, unverified 'from' domain, recipient on suppression/bounce list, payload too large, or rate limit exceeded.","commonSituations":"Testing against localhost with a real API key but an unverified sending domain (onboarding.validate_from not satisfied), using onboarding@resend.dev as from while sending to arbitrary addresses, key rotated or deleted in the Resend dashboard, or 429s during bulk sends.","solutions":["Read the message after the prefix — it states the concrete Resend failure (e.g. 'You can only send testing emails to your own email address')","Verify the sending domain in the Resend dashboard and set RESEND_EMAIL_FROM to an address on that domain","Confirm RESEND_API_KEY is a valid, non-revoked full-access key for the account that owns the domain","Check Resend status page / rate limits if the message indicates a 4xx throttling or 5xx issue and retry with backoff"],"exampleFix":"// before\nfrom: 'onboarding@resend.dev' // works only for your own account's email\n// after\n// verify your domain in Resend, then set RESEND_EMAIL_FROM\nfrom: 'noreply@notifications.yourdomain.com'","handlingStrategy":"try-catch","validationCode":"// pre-flight: check config before calling\nif (!env.RESEND_API_KEY) throw new Error('RESEND_API_KEY missing');\nconst fromDomain = env.RESEND_EMAIL_FROM.split('@')[1];\nif (!fromDomain || fromDomain === 'resend.dev') {\n  console.warn('Sending from an unverified domain — Resend will likely reject');\n}","typeGuard":"function isResendApiError(error: unknown): error is Error & { message: string } {\n  return error instanceof Error && error.message.startsWith('Resend API error:');\n}","tryCatchPattern":"try {\n  await sendEmail(env, options);\n} catch (error) {\n  const msg = error instanceof Error ? error.message : String(error);\n  if (msg.includes('Resend API error:')) {\n    const detail = msg.split('Resend API error:')[1]?.trim();\n    // 4xx config/auth problems are not retryable; log detail and alert\n    console.error('Resend rejected the send:', detail);\n    return { ok: false, retryable: false };\n  }\n  throw error;\n}","preventionTips":["Verify your sending domain in Resend before production sends and keep RESEND_EMAIL_FROM on it","Monitor for key revocation: a health-check send or dashboard alert on API key changes","In dev, send only to your own account's email address when using onboarding@resend.dev","Rate-limit bulk sends and back off on 429s"],"tags":["resend","api","email","network"],"backgroundTag":"resend-api-error","analyzedSha":"0aa7603435f16159ad0b8fef68fb7f6280be7ca1","analyzedAt":"2026-08-31T21:50:55.742Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}