rails_event_store icon indicating copy to clipboard operation
rails_event_store copied to clipboard

Better error handling for Browser

Open mostlyobvious opened this issue 4 years ago • 0 comments

Consider following scenario:

  • broken events JSON from backend (i.e. missing timestamp key in metadata, i.e. due to misconfigured Event class like #762)

    {
      "data": [
          {
              "id": "c6fcd01d-b708-46a7-b712-18783cc6e880",
              "type": "events",
              "attributes": {
                  "event_type": "DummyEvent",
                  "data": {
                      "some_integer_attribute": 42,
                      "some_string_attribute": "foobar",
                      "some_float_attribute": 3.14
                  },
                  "metadata": {},
                  "correlation_stream_name": "$by_correlation_id_469904c5-46ee-43a3-857f-16a455cfe337",
                  "causation_stream_name": "$by_causation_id_c6fcd01d-b708-46a7-b712-18783cc6e880",
                  "type_stream_name": "$by_type_DummyEvent",
                  "parent_event_id": null
              }
          }
    ]
    
  • event decoder expecting timestamp to be present and generating Err on lack of it

    eventDecoder_ : Decoder Event
    eventDecoder_ =
        succeed Event
            |> requiredAt [ "attributes", "event_type" ] string
            |> requiredAt [ "id" ] string
            |> requiredAt [ "attributes", "metadata", "timestamp" ] Iso8601.decoder
            |> requiredAt [ "attributes", "data" ] (value |> Json.Decode.map (encode 2))
            |> requiredAt [ "attributes", "metadata" ] (value |> Json.Decode.map (encode 2))
            |> optionalAt [ "attributes", "correlation_stream_name" ] (maybe string) Nothing
            |> optionalAt [ "attributes", "causation_stream_name" ] (maybe string) Nothing
            |> requiredAt [ "attributes", "type_stream_name" ] string
            |> optionalAt [ "attributes", "parent_event_id" ] (maybe string) Nothing
    
    ▾GotShowStreamMsg EventsFetched …
    ▾0 = Err BadBody …
     0 = "Problem with the value at json.data[0].attributes.metadata:\n\n {}\n\nExpecting an OBJECT with a field named `timestamp`"
    
  • handling of Err in update

            EventsFetched (Err errorMessage) ->
              ( model, Cmd.none )
    
  • view on initial data being optimistic

    renderResults baseUrl events =
       case events of
            [] ->
                p [ class "results__empty" ] [ text "No items" ]
    
    

We end up with empty page suggesting no items like no error ever happened. Backend logs show to clue either -- all is good there.

mostlyobvious avatar Dec 10 '20 20:12 mostlyobvious