Skip to content

A library that combines Simple-JSON, Milkis (Fetch), and Chirashi (Error subtypes).

License

Notifications You must be signed in to change notification settings

justinwoo/purescript-ochadzuke

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Purescript-Ochadzuke

A library that combines Simple-JSON, Milkis (Fetch), and Chirashi (Error subtypes).

It's ochadzuke made by mixing Chirashi and Milkis.

Usage

main :: Effect Unit
main = Aff.launchAff_ do

  -- works normally
  normal <- fetch' testUrl O.defaultFetchOptions'
  assertEqual'
    { expected: { "userId": 1 }
    , actual: normal
    }

  -- gives an error in readForeign on mismatched decoding type
  wrong <- Aff.attempt $ fetch' testUrl O.defaultFetchOptions'
  case wrong of
    Left e
      | Just (variant :: O.Error) <- C.readVariant e
      , Just multipleErrors <- V.prj O.readForeignS variant -> do
      pure unit
    Right (e :: { asdf :: String }) -> Aff.throwError $ Aff.error "False parsing result"
    Left e ->
      Aff.throwError e

  -- gives an error in otherS on random other failure
  wrong2 <- Aff.attempt $ fetch' (M.URL "sdflsjdfasdf") O.defaultFetchOptions'
  case wrong2 of
    Left e
      | Just (variant :: O.Error) <- C.readVariant e
      , Just other <- V.prj O.otherS variant ->
      assertEqual'
        { expected: "TypeError: Only absolute URLs are supported"
        , actual: Aff.message other
        }
    Right (e :: {}) -> Aff.throwError $ Aff.error "False parsing result"
    Left e -> Aff.throwError e

See the API Docs or the tests for usage.

About

A library that combines Simple-JSON, Milkis (Fetch), and Chirashi (Error subtypes).

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published