Handle context cancellations and avoid logged errors.
This commit is contained in:
parent
0f7da0864e
commit
acd38c8205
8 changed files with 83 additions and 35 deletions
|
|
@ -1,5 +1,10 @@
|
|||
package context
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
)
|
||||
|
||||
const (
|
||||
// AuthenticatedUserKey is the key value used to store the authenticated user in context
|
||||
AuthenticatedUserKey = "auth_user"
|
||||
|
|
@ -13,3 +18,8 @@ const (
|
|||
// PasswordTokenKey is the key value used to store a password token in context
|
||||
PasswordTokenKey = "password_token"
|
||||
)
|
||||
|
||||
// IsCanceledError determines if an error is due to a context cancelation
|
||||
func IsCanceledError(err error) bool {
|
||||
return errors.Is(err, context.Canceled)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue