Giter Site home page Giter Site logo

Comments (4)

ConnorJBishop avatar ConnorJBishop commented on May 19, 2024 1

Landed here wanting to return ProblemDetails myself. Would be a nice to have but as @JonPSmith mentioned its not too difficult to add this in yourself. I achieved it with a BaseController and the following method:

public class BaseController : ControllerBase
{
    public ActionResult<WebApiMessageOnly> WebApiResponse(IStatusGeneric status)
    {
        if (status.IsValid)
        {
            return status.Response();
        }

        status.CopyErrorsToModelState(ModelState);

        return ValidationProblem(ModelState);
    }
}

from efcore.genericservices.aspnetcore.

JonPSmith avatar JonPSmith commented on May 19, 2024

Hi @kcaswick,

There are two issues here:

  1. Is it worth adding support for the ProblemDetails class?
  2. The EfCore.GenericServices.AspNetCore uses Microsoft.AspNetCore.Mvc.Core Version="2.1.1"

Taking the "is it worth adding support for the ProblemDetails class" issue I would say no, as:

  • The ProblemDetails class is aimed at turning exceptions into a better return in an Web API
  • Its pretty easy to manually convert a IStatusGeneric to a ProblemDetail - see the ProblemDetail properties

The "EfCore.GenericServices.AspNetCore uses a out of date version of Microsoft.AspNetCore.Mvc.Core" issue is a good point and at some time I will update it, BUT due to the NuGet definition the latest version of AspNetCore.Mvc.Core used by your app replaces the 2.1 version. And beacause this library uses only the very basic parts of AspNetCore, like ActionResult<T> there isn't a problem.

I'm quite busy at the moment so I won't updating this library to the latest AspNetCore version - maybe when I update any of my libraries to .NET 6. I will leave this issue open to remind me.

from efcore.genericservices.aspnetcore.

JonPSmith avatar JonPSmith commented on May 19, 2024

Thanks @ConnorJBishop for that. I plan to update the libraries to 3.1 and I might add a status.ConvertToProblemDetails() extension method at the same time.

from efcore.genericservices.aspnetcore.

kcaswick avatar kcaswick commented on May 19, 2024

I believe my bigger concern had been a 3rd issue, that WebApiMessageAndResult was consistent with the old error response, but not ProblemDetails, so the consistency in format between success and failure responses was lost. If I remember right, Hellang.Middleware.ProblemDetails took care of converting a BadRequestObjectResult to ProblemDetails.

However since then OData became a requirement for my project, and it has its own special error format to return anyway. I'd be fine with closing this issue, unless you want to leave it open for others.

from efcore.genericservices.aspnetcore.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.