Skip to content

Commit 8e00824

Browse files
committed
Refactor error handling in BewitAuthorizationMiddleware to provide a more descriptive authorization failure message.
1 parent 423dcab commit 8e00824

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Extensions.HotChocolate/Validation/BewitAuthorizationMiddleware.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ public async Task InvokeAsync(IMiddlewareContext context)
5555
private void CreateError(IMiddlewareContext context, Exception ex = default)
5656
{
5757
IErrorBuilder errorBuilder = ErrorBuilder.New()
58-
.SetMessage("NotAuthorized")
59-
.SetPath(context.Path)
60-
.AddLocation(context.Selection.SyntaxNode);
58+
.SetMessage("The current user is not authorized to access this resource.")
59+
.SetCode(ErrorCodes.Authentication.NotAuthorized);
6160

6261
if (ex != default)
6362
{
6463
errorBuilder.SetException(ex);
6564
}
6665

66+
context.ContextData[WellKnownContextData.HttpStatusCode] = 401;
6767
context.Result = errorBuilder.Build();
6868
}
6969
}

0 commit comments

Comments
 (0)