cofoundry-cms / cofoundry

Cofoundry is an extensible and flexible .NET Core CMS & application framework focusing on code first development
https://www.cofoundry.org
MIT License
820 stars 144 forks source link

Please consider using JSON "Problem Details for HTTP APIs" for returning errors #416

Open JornWildt opened 3 years ago

JornWildt commented 3 years ago

I have noticed that the automatic validation performed by ASP.NET Core utilizes "Problem Details for HTTP APIs" (https://tools.ietf.org/html/rfc7807) which is a Internet standard for reporting errors in JSON. See for instance https://docs.microsoft.com/en-us/aspnet/core/web-api/handle-errors?view=aspnetcore-5.0#validation-failure-error-response.

But Cofoundry has it's own error format when returning errors from ApiResponseHelper.RunCommandAsync - which means JavaScript code has to handle two different error formats. Not a big deal but still annoying.

I know it won't be backwards compatible, so a global setting is probably needed, but it would be nice if Cofoundry returns the same error format as ASP.NET Core does.

HeyJoel commented 3 years ago

IApiResponseHelper is deliberately separate to the ASP.NET Core controller configuration so that any changes you make to the ASP.NET defaults don't break the admin panel, and visa versa - we don't want to have to tinker with your ASP.NET defaults and break your application. It's optional for you to use IApiResponseHelper, but it's good to know you're finding it useful and would like it improved.

It was developed a long time ago so it's probably due a refresh, so I'll take a closer look at the problem details spec and see if we can align what we do to it. There's a few other bits that the ASP.NET team have added to web API default recently that are also probably worth looking at too.