@@ -5,14 +5,13 @@ import (
5
5
"database/sql"
6
6
"fmt"
7
7
8
+ "github.com/google/uuid"
8
9
"golang.org/x/xerrors"
9
10
10
11
"cdr.dev/slog"
11
-
12
- "github.com/google/uuid"
13
-
14
12
"github.com/coder/coder/coderd/database"
15
13
"github.com/coder/coder/coderd/rbac"
14
+ "github.com/open-policy-agent/opa/topdown"
16
15
)
17
16
18
17
var _ database.Store = (* querier )(nil )
@@ -44,11 +43,18 @@ func logNotAuthorizedError(ctx context.Context, logger slog.Logger, err error) e
44
43
// Only log the errors if it is an UnauthorizedError error.
45
44
internalError := new (rbac.UnauthorizedError )
46
45
if err != nil && xerrors .As (err , & internalError ) {
47
- logger .Debug (ctx , "unauthorized" ,
48
- slog .F ("internal" , internalError .Internal ()),
49
- slog .F ("input" , internalError .Input ()),
50
- slog .Error (err ),
51
- )
46
+ // A common false flag is when the user cancels the request. This can be checked
47
+ // by checking if the error is a topdown.Error and if the error code is
48
+ // topdown.CancelErr. If the error is not a topdown.Error, or the code is not
49
+ // topdown.CancelErr, then we should log it.
50
+ e := new (topdown.Error )
51
+ if ! xerrors .As (err , & e ) || e .Code != topdown .CancelErr {
52
+ logger .Debug (ctx , "unauthorized" ,
53
+ slog .F ("internal" , internalError .Internal ()),
54
+ slog .F ("input" , internalError .Input ()),
55
+ slog .Error (err ),
56
+ )
57
+ }
52
58
}
53
59
return NotAuthorizedError {
54
60
Err : err ,
0 commit comments