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.
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.