Fix: Correctly handle ErrInvalidSignature comparison #429
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.
Background
While integrating LINE webhook events, I noticed an inconsistency in how errors, specifically ErrInvalidSignature, were being handled. The direct comparison of errors using == does not effectively catch ErrInvalidSignature due to the way Go's error interface works. This led to improper HTTP status codes being returned, affecting the error feedback mechanism.
Changes Made
This PR addresses the issue by updating the error comparison logic in both echo_bot and kitchensink examples. Instead of directly comparing error interfaces, the changes involve comparing the error messages:
In echo_bot/server.go and kitchensink/server.go, modified the conditional checks from if err == linebot.ErrInvalidSignature to if err.Error() == linebot.ErrInvalidSignature.Error(). This ensures that the error comparison is based on the error message string, which is a more reliable method for this scenario.
By the way,I have tried using errors.Is(err, linebot.ErrInvalidSignature)
But still can't work
Version
go version go1.21.3 darwin/arm64