Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: log API errors in non-production environments#763

Open
vieiralucas wants to merge 1 commit into
canaryfrom
feat/error-logging-non-production
Open

feat: log API errors in non-production environments#763
vieiralucas wants to merge 1 commit into
canaryfrom
feat/error-logging-non-production

Conversation

@vieiralucas

@vieiralucas vieiralucas commented Dec 1, 2025

Copy link
Copy Markdown
Member

Summary by cubic

Adds structured console logging for Resend API errors in non-production to make debugging easier. Production behavior is unchanged.

  • New Features
    • Logs “[Resend API Error]” with status, error payload, and path when API calls fail (non-production only).
    • Normalizes error objects for JSON parse failures, generic errors, and network errors.
    • Logging gated by NODE_ENV !== 'production'.

Written for commit 401471d. Summary will update automatically on new commits.

@vieiralucas vieiralucas requested a review from a team as a code owner December 1, 2025 11:02
@vieiralucas vieiralucas requested a review from rehanvdm December 1, 2025 11:02
@pkg-pr-new

pkg-pr-new Bot commented Dec 1, 2025

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/resend/resend-node/resend@763

commit: 401471d

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file

Prompt for AI agents (all 1 issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="src/resend.ts">

<violation number="1" location="src/resend.ts:77">
P2: `process.env` is accessed without guarding that `process` exists, so any non-Node runtime (e.g., Cloudflare Workers) will throw a ReferenceError as soon as an error response goes through this branch. Guard the `process` access before checking `NODE_ENV`, and apply the same guard to the other new logging blocks.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

Comment thread src/resend.ts Outdated
const rawError = await response.text();
const parsedError = JSON.parse(rawError);

if (process.env.NODE_ENV !== 'production') {

@cubic-dev-ai cubic-dev-ai Bot Dec 1, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: process.env is accessed without guarding that process exists, so any non-Node runtime (e.g., Cloudflare Workers) will throw a ReferenceError as soon as an error response goes through this branch. Guard the process access before checking NODE_ENV, and apply the same guard to the other new logging blocks.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/resend.ts, line 77:

<comment>`process.env` is accessed without guarding that `process` exists, so any non-Node runtime (e.g., Cloudflare Workers) will throw a ReferenceError as soon as an error response goes through this branch. Guard the `process` access before checking `NODE_ENV`, and apply the same guard to the other new logging blocks.</comment>

<file context>
@@ -72,21 +72,41 @@ export class Resend {
           const rawError = await response.text();
+          const parsedError = JSON.parse(rawError);
+
+          if (process.env.NODE_ENV !== &#39;production&#39;) {
+            console.error(&#39;[Resend API Error]:&#39;, {
+              status: response.status,
</file context>
Suggested change
if (process.env.NODE_ENV !== 'production') {
if (
typeof process !== 'undefined' &&
process.env &&
process.env.NODE_ENV !== 'production'
) {
Fix with Cubic

@vieiralucas vieiralucas force-pushed the feat/error-logging-non-production branch from fc6c355 to 401471d Compare December 1, 2025 12:11

@rehanvdm rehanvdm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just to have better observability? And make it easier to debug by not adding many console logs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants