debuggoModerate
How to compare Go errors
Viewed 0 times
errorshowcompare
Problem
I have an error value which when printed on console gives me
How can I compare it with a specific error value? I tried this but it did not work:
Token is expiredHow can I compare it with a specific error value? I tried this but it did not work:
if err == errors.New("Token is expired") {
log.Printf("Unauthorised: %s\n", err)
}Solution
Try
Or create your own error by implementing the error interface.
err.Error() == "Token is expired"Or create your own error by implementing the error interface.
Code Snippets
err.Error() == "Token is expired"Context
Stack Overflow Q#39121172, score: 36
Revisions (0)
No revisions yet.