Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I fill errors #158

Closed
michaelakin opened this issue Oct 18, 2022 · 4 comments
Closed

How do I fill errors #158

michaelakin opened this issue Oct 18, 2022 · 4 comments

Comments

@michaelakin
Copy link

I have tried a few things and don't see any difference for RootCause and I wonder how to fill in the errors instead of Reasons.

Here is my code:

                catch (Exception ex)
                {
                    var error = new Error(ex.Message);
                    return Results.BadRequest(Result.Fail(new Error(ex.Message).CausedBy(ex)));
                }

And here is what I got as a result:

{
  "isFailed": true,
  "isSuccess": false,
  "reasons": [
    {
      "message": "Invalid code provided, please request a code again.",
      "metadata": {}
    }
  ],
  "errors": [
    {
      "reasons": [
        {
          "reasons": []
        }
      ]
    }
  ],
  "successes": []
}

I am sure I missed something in the documentation.

Also, how have people converted the results of FluentValidation into your model so we only return 1 type of object back instead of several different kinds of error models.

@michaelakin michaelakin changed the title How to fill errors: How do I fill errors Oct 18, 2022
@altmann
Copy link
Owner

altmann commented Oct 19, 2022

Hi,

  • if you debug the result object before you pass it in the BadRequest() method then you should see one error object in the Errors property of the result object. This error object should have a property Reasons which contain one ExceptionalError object with the property Exception. This property should contain your exception. If you can't see that please let me know. I also debugged it in my test suite and there it works.
  • Please don't serialize result objects - result objects are not designed to serialize it. Because of that you see a json in your scenario which is is not perfect. Details see

@michaelakin
Copy link
Author

Since we should not serialize the object, I think you are saying to not use this as the return object for WebApi calls. Am I understanding this correctly?

@altmann
Copy link
Owner

altmann commented Oct 19, 2022

yes thats correct. Iam currently create a new package exactly for that scenario - details see #149
I think I will release a preview version of it in the next weeks.

@michaelakin
Copy link
Author

Thanks, I will look for it, but I have to create something now I think.

@altmann altmann closed this as completed Oct 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants