HiveBrain v1.2.0
Get Started
← Back to all entries
debuggoModerate

How to compare Go errors

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
errorshowcompare

Problem

I have an error value which when printed on console gives me Token is expired

How 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

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.