Skip to content

fix: replace console.log with debug logger in createValidateStatusCode#829

Open
Juan Ibiapina (juanibiapina-ctfl) wants to merge 3 commits into
mainfrom
remove-console-log
Open

fix: replace console.log with debug logger in createValidateStatusCode#829
Juan Ibiapina (juanibiapina-ctfl) wants to merge 3 commits into
mainfrom
remove-console-log

Conversation

@juanibiapina-ctfl
Copy link
Copy Markdown

@juanibiapina-ctfl Juan Ibiapina (juanibiapina-ctfl) commented Jun 2, 2026

createValidateStatusCode unconditionally called console.log(response.body) before throwing HTTPError on any unexpected status code. This bypasses any structured logger in the consuming application and writes raw JSON directly to stdout.

In Grafana/Loki environments each line of the JSON body is ingested as a separate log entry at error level with no extractable message field, causing significant observability noise (e.g. 550k+ entries/month from 404s on deleted app installations in our Grafana).

Following review feedback, the console.log is replaced with the package's existing debug logger, gated behind DEBUG=@contentful/node-apps-toolkit*. This means it is silent by default in production but available for local debugging when needed.

This change also adds the first unit tests for createValidateStatusCode, including an explicit assertion that no stdout output occurs when the error path fires.

Comment thread src/utils/http.ts

export const createValidateStatusCode = (allowedStatusCodes: number[]) => (response: Response) => {
if (!allowedStatusCodes.includes(response.statusCode)) {
console.log(response.body)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

debug might be better here instead of removing it completely

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

good idea

Use the package's existing debug logger (gated by DEBUG=@contentful/node-apps-toolkit*)
instead of console.log, so the output is silent by default in production.
@juanibiapina-ctfl Juan Ibiapina (juanibiapina-ctfl) changed the title fix: Remove console.log on invalid status codes fix: replace console.log with debug logger in createValidateStatusCode Jun 3, 2026
@jmtoball
Copy link
Copy Markdown

Do we have a ticket for this we could add to the title for context?

Copy link
Copy Markdown
Contributor

@BobHemphill76 BobHemphill76 left a comment

Choose a reason for hiding this comment

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

Just want to make sure that this commit gets tied to a ticket, but otherwise looks good

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.

4 participants