Skip to content

Marketing skills for Claude Code and AI agents. CRO, copywriting, SEO, analytics, and growth engineering.

fix: fail Resend CLI on rejected API responses

agammann4182b3fbaee5
diff --git a/tests/clis/resend-error-exit.test.cjs b/tests/clis/resend-error-exit.test.cjs
new file mode 100644
index 0000000..aeab2dd
--- /dev/null
+++ b/tests/clis/resend-error-exit.test.cjs
@@ -0,0 +1,24 @@
+const { test } = require('node:test')
+const assert = require('node:assert/strict')
+const { spawnSync } = require('node:child_process')
+const path = require('node:path')
+
+test('Resend API rejection causes a failing CLI exit status', () => {
+ const cli = path.resolve(__dirname, '../../tools/clis/resend.js')
+ const source = `
+ global.fetch = async () => ({
+ status: 400,
+ text: async () => JSON.stringify({ name: 'validation_error', message: 'API key is invalid' }),
+ })
+ process.argv = ['node', ${JSON.stringify(cli)}, 'domains', 'list']
+ require(${JSON.stringify(cli)})
+ `
+ const result = spawnSync(process.execPath, ['-e', source], {
+ encoding: 'utf8',
+ timeout: 5000,
+ env: { ...process.env, RESEND_API_KEY: 'invalid-test-key' },
+ })
+
+ assert.equal(result.status, 1, result.stderr || result.stdout)
+ assert.match(result.stdout, /API key is invalid/)
+})
diff --git a/tools/clis/resend.js b/tools/clis/resend.js
index 555677b..350f72e 100755
--- a/tools/clis/resend.js
+++ b/tools/clis/resend.js
@@ -22,6 +22,7 @@ async function api(method, path, body) {
body: body ? JSON.stringify(body) : undefined,
})
const text = await res.text()
+ if (res.status >= 400) process.exitCode = 1
try {
return JSON.parse(text)
} catch {