Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 306c591

Browse files
committed
Correct the returned error from not authorized
1 parent 57ab200 commit 306c591

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

coderd/database/dbauthz/dbauthz.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ func logNotAuthorizedError(ctx context.Context, logger slog.Logger, err error) e
5555
slog.F("input", internalError.Input()),
5656
slog.Error(err),
5757
)
58+
} else {
59+
// For some reason rego changes a cancelled context to a topdown.CancelErr. We
60+
// expect to check for cancelled context errors if the user cancels the request,
61+
// so we should change the error to a context.Canceled error.
62+
//
63+
// NotAuthorizedError is == to sql.ErrNoRows, which is not correct
64+
// if it's actually a cancelled context.
65+
internalError.SetInternal(context.Canceled)
66+
return internalError
5867
}
5968
}
6069
return NotAuthorizedError{

coderd/rbac/error.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ func (e *UnauthorizedError) Internal() error {
6161
return e.internal
6262
}
6363

64+
func (e *UnauthorizedError) SetInternal(err error) {
65+
e.internal = err
66+
}
67+
6468
func (e *UnauthorizedError) Input() map[string]interface{} {
6569
return map[string]interface{}{
6670
"subject": e.subject,

0 commit comments

Comments
 (0)