fix(follow): track success with boolean flag instead of reply.statusCode#153
Draft
anshul23102 wants to merge 1 commit into
Draft
fix(follow): track success with boolean flag instead of reply.statusCode#153anshul23102 wants to merge 1 commit into
anshul23102 wants to merge 1 commit into
Conversation
reply.statusCode was checked after followGitHub() returned, but Fastify sets statusCode to 200 by default before reply.send() is called with a non-error body. This caused the follow log to always record 'success' even when the request failed. Fixed by returning a boolean from followGitHub() that is true only when GitHub responds with 204, and using that to decide whether to log success.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #148
What was wrong
In
follow.ts, after callingfollowGitHub(), the code checkedreply.statusCodeto decide whether to log a success. However, Fastify initialisesstatusCodeto200before any handler runs. The success path insidefollowGitHub()callsreply.send({ status: 'success', ... })without setting a status code, soreply.statusCodestays at 200. The conditionreply.statusCode === 200 || reply.statusCode === 204therefore always evaluated to true, logging every follow attempt as a success even when it failed.What changed
followGitHub()now returnsPromise<boolean>-trueonly when GitHub responds with204 No Content.reply.send()/reply.status().send()calls are no longer mixed with a statusCode check after the fact.Type of change