reflex-dom icon indicating copy to clipboard operation
reflex-dom copied to clipboard

WIP: Fix definition of success in newXMLHttpRequestWithError

Open TheKK opened this issue 3 years ago • 0 comments

Here the sample code demonstrates this change:

example :: (MonadWidget t m) => m ()
example = mdo
  failureE <- button "failure"

  divClass "" $ do
    text "getAndDecode"
    simpleList e1Dyn $ el "li" . display

  divClass "" $ do
    text "performRequestAsync"
    simpleList e2Dyn $ el "li" . display

  divClass "" $ do
    text "performRequestAsyncWithError"
    simpleList e3Dyn $ el "li" . display

  e1E :: Event t (Maybe ()) <- getAndDecode
     $ "https://nnnnnnnnnnn"
    <$ failureE

  e2E :: Event t XhrResponse <- performRequestAsync
     $ xhrRequest "GET" "https://nnnnnnnnnnn" def
    <$ failureE

  e3E :: Event t (Either XhrException XhrResponse) <- performRequestAsyncWithError
     $ xhrRequest "GET" "https://nnnnnnnnnnn" def
    <$ failureE

  e1Dyn <- foldDyn (:) [] e1E
  e2Dyn <- foldDyn (:) [] $ fmap (_xhrResponse_statusText) e2E
  e3Dyn <- foldDyn (:) [] $ fmap (fmap _xhrResponse_status) e3E

  return ()

Before this change, press the button to cause Xhr error and you got: a

After this change, press the button to cause Xhr error and you got: b

It's great that performRequestAsyncWithError stops returning Right 0 on error and reports exception correctly. But now performRequestAsync and getAndDecode become silent, which would need some discussion.

In the case of performRequestAsync, it's appropriate to keep silence on error since it return Event t XhrResponse and we won't get one on the error case.

For getAndDecode which creates Event t (Maybe a), should we map Xhr error to Nothing or not emitting this event?

TheKK avatar Apr 27 '21 18:04 TheKK