Do not forget to setup elm-ffi (README)
Create a JS aync function from Elm, with its parameters
fetchJson : { url: String } -> Task Error Value
fetchJson =
FFI.function
[ ( "url", .url >> Json.Encode.string )
]
"""
let res = await fetch(url)
if (!res.ok) throw res.statusText
return await res.json()
"""Decode values within a Task Error Value
fetchedUser : Task FFI.Error User
fetchedUser =
fetchUser
|> FFI.decode decodeUserRepresenting JS errors
usually a JS object with a name and a message
Explain why a Task failed providing error's name and message
error : Task FFI.Error a
error =
FFI.fail "Some Error" "Some cause or solution"Get a readable error
Quickly access global values