0

Been having issue receiving errors on my Blazor client that occur during a graphql query on my Blazor Server. Using an error filter, when an exception is thrown during execution on the server side the error is added to Errors.

Banana Cake Pop Response showing the error thrown added to errors. Banana Cake Pop Response showing the error thrown added to errors

try
{
    var test = await graphQlClient.TestError.ExecuteAsync();
    if (test.IsErrorResult())
    {
        foreach(IClientError error in test.Errors) 
        { 
             _logger.LogError(error.Message);
        }
    }            
}
catch (Exception ex)
{
    ///Catch
}

But the result received by the client, test.Errors contains one error with the message of, 'Response status code does not indicate success: 500 (Internal Server Error).', rather than the one error thrown on the server("message": "Access is denied 123.").

As seen in the picture above, in Banana Cake Pop the status code returns as 500 when an exception is thrown during the query execution but why does the Errors[] received by the client contain the HTTP response error rather than the errors received during execution? Are hot chocolate error filters used to return errors to developers(Using BCP) and not the client?

Using the approach described in this article, I would return an ObjectResult containing a collection of errors received during execution rather than throwing an exception which causes the query to fail. Is there a way to return an exception message thrown by the server in Errors[] result on my client or is the best approach to use a ObjectResult? Please describe why if so or a proper fix to return errors to the client. Thank you.

Peter Csala
  • 17,736
  • 16
  • 35
  • 75
  • Use the Network tab on your browser's F12 tools to see what's sent and received by Banana Cake Pop. If your client makes the same request to the same server it should receive the same response. It's possible the error occurred *before* reaching HotChocolate though. A 500 is a server crash. Did you check the web app's logs? – Panagiotis Kanavos Apr 06 '23 at 07:51
  • You can try running the web app from the command line or [redirect the web app's stdout to a file](https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/logging-and-diagnostics?view=aspnetcore-7.0) in IIS to see what happened even if logging isn't enabled – Panagiotis Kanavos Apr 06 '23 at 07:54

0 Answers0