Eventuous / eventuous

Event Sourcing library for .NET
https://eventuous.dev
Apache License 2.0
447 stars 71 forks source link

Follow RFC 7807: Problem Details for HTTP APIs #242

Closed Frikki closed 9 months ago

Frikki commented 1 year ago

Is your feature request related to a problem? Please describe. When all HTTP APIs define their own “error” JSON objects, it becomes a nightmare for developers to remember or find which members are available. And it’s hard for machines to read them.

Describe the solution you'd like RFC 7807: Problem Details for HTTP APIs already reached consensus in the IETF community on how to define a “problem detail” as a way to carry machine-readable details of errors in an HTTP response to avoid the need to define new error response formats for HTTP APIs, not to replace existing domain-specific formats.

It would be super if Eventuous would follow the standard and be a role model like it is for Event Sourcing. Section 3 details the members of a Problem Detail Object.

Describe alternatives you've considered

Additional context

Here is an example of what the current 400 Bad Request response looks like:

HTTP/1.1 400 Bad Request
   Content-Type: application/json
   Content-Language: en

{
  "errorMessage": "Unable to append events to Booking-123: Type RoomBooked is not registered in the type map",
  "message": "Error handling command BookRoom",
  "state": null,
  "success": false,
  "changes": null
}

Here is an example of what a 400 Bad Request response with problem details would look like:

HTTP/1.1 400 Bad Request
   Content-Type: application/problem+json
   Content-Language: en

{
    "type": "https://eventuous.dev/errors/unable-to-handle-command",
    "title": "Unable to handle command",
    "status": 400,
    "detail": "Unable to append events to Booking-123: Type RoomBooked is not registered in the type map. See https://eventuous.dev/docs/persistence/serialisation/#type-map",
    "instance": "/bookings/book",
    "success": false,
    "state": null,
    "changes": null
}
makp0 commented 1 year ago

@Frikki, could you please include before for ease of comparison?

Frikki commented 1 year ago

Sure thing, @makp0. Updated OP.

Frikki commented 1 year ago

While inspecting the Eventuous source code, I noticed that Eventuous.AspNetCore.Web’s ResultExtension uses ProblemDetails from Microsoft.AspNetCore.Web.

An article at CodeMaze also addresses the issue and the standard implemented in ASP.NET Core Web API.

alexeyzimarev commented 10 months ago

Does the latest preview version cover these needs?