Closed thomastvedt closed 1 year ago
In the generated code:
public global::StrawberryShake.IOperationResult<ISaveUserEmailResult> Build(global::StrawberryShake.Response<global::System.Text.Json.JsonDocument> response)
{
(ISaveUserEmailResult Result, SaveUserEmailResultInfo Info)? data = null;
global::System.Collections.Generic.IReadOnlyList<global::StrawberryShake.IClientError>? errors = null;
if (response.Exception is null)
{
try
{
if (response.Body != null)
{
if (response.Body.RootElement.TryGetProperty("data", out global::System.Text.Json.JsonElement dataElement) && dataElement.ValueKind == global::System.Text.Json.JsonValueKind.Object)
{
data = BuildData(dataElement);
}
if (response.Body.RootElement.TryGetProperty("errors", out global::System.Text.Json.JsonElement errorsElement))
{
errors = global::StrawberryShake.Json.JsonErrorParser.ParseErrors(errorsElement);
}
}
}
catch (global::System.Exception ex)
{
errors = new global::StrawberryShake.IClientError[]{new global::StrawberryShake.ClientError(ex.Message, exception: ex, extensions: new global::System.Collections.Generic.Dictionary<global::System.String, global::System.Object?>{{"body", response.Body?.RootElement.ToString()}})};
}
}
else
{
errors = new global::StrawberryShake.IClientError[]{new global::StrawberryShake.ClientError(response.Exception.Message, exception: response.Exception, extensions: new global::System.Collections.Generic.Dictionary<global::System.String, global::System.Object?>{{"body", response.Body?.RootElement.ToString()}})};
}
return new global::StrawberryShake.OperationResult<ISaveUserEmailResult>(data?.Result, data?.Info, _resultDataFactory, errors);
}
I guess response.Exception
is not null. The GraphQL request returns http status 500. So the strawberryshake client handles this as a "serious" unknown 500 bad exception? Am I supposed to return http status code 200 from the server in this case?
If I add a custom IHttpResultSerializer and make sure that my server returns http status code 200 for my custom, "expected" errors, everything is mapped ok in StrawberryShake.
But I'm still not sure how this is supposed to work.
Am I supposed to return http status 200 for "known errors"?
GraphQL doesn't really care about http status codes, perhaps SS shouldn't care either?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
@michaelstaib @PascalSenn I'd like to take a crack at this one
Are you on slack? Slack.Chillicream.com? Ping me there
Just pinged you
This issue is now fixed.
Is there an existing issue for this?
Describe the bug
I expected my StrawberryShake client to return error codes from the GraphQL response, but
result.Errors[0].Code
is null. The error code can be found insideresult.Errors[0].Extensions["body"]
, but I assume that this is not how this is intended to work? Perhaps some sort of serialization bug?I made a quick reproduction here: https://github.com/thomastvedt/HotChocolateBug
The following mutation:
results in the following GraphQL response:
When running the console app with the generated StrawberryShake client I get the following result:
I was expecting to find my
CUSTOM_ERROR_CODE
underresult.Errors[0].Code
, but this isnull
.Is this a bug or expected?
Steps to reproduce
I made a quick reproduction here: https://github.com/thomastvedt/HotChocolateBug
Relevant log output
No response
Additional Context?
No response
Product
Strawberry Shake
Version
12.4.1