mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-27 05:44:17 +03:00
Make DataSource.Port error catchable.
This commit is contained in:
parent
1f109fca7c
commit
6bd91eb68e
@ -100,6 +100,7 @@ data routeParams =
|
||||
(DataSource.Port.get "getItems"
|
||||
Encode.null
|
||||
(Decode.list Decode.string)
|
||||
|> DataSource.throw
|
||||
|> DataSource.map
|
||||
(\items ->
|
||||
Server.Response.render
|
||||
@ -127,6 +128,7 @@ action routeParams =
|
||||
DataSource.Port.get "addItem"
|
||||
(Encode.string newItem)
|
||||
(Decode.list Decode.string)
|
||||
|> DataSource.throw
|
||||
|> DataSource.map
|
||||
(\_ ->
|
||||
Server.Response.render ActionData
|
||||
@ -136,6 +138,7 @@ action routeParams =
|
||||
DataSource.Port.get "deleteAllItems"
|
||||
Encode.null
|
||||
(Decode.list Decode.string)
|
||||
|> DataSource.throw
|
||||
|> DataSource.map
|
||||
(\_ ->
|
||||
Server.Response.render ActionData
|
||||
|
@ -53,7 +53,7 @@ data : DataSource Throwable Data
|
||||
data =
|
||||
DataSource.map2 Data
|
||||
(DataSource.File.rawFile "greeting.txt" |> DataSource.throw)
|
||||
(DataSource.Port.get "hello" (Encode.string "Jane") Decode.string)
|
||||
(DataSource.Port.get "hello" (Encode.string "Jane") Decode.string |> DataSource.throw)
|
||||
|
||||
|
||||
head :
|
||||
|
@ -14,6 +14,7 @@ module DataSource.Port exposing
|
||||
import DataSource
|
||||
import DataSource.Http
|
||||
import DataSource.Internal.Request
|
||||
import Exception exposing (Catchable)
|
||||
import Json.Decode exposing (Decoder)
|
||||
import Json.Encode as Encode
|
||||
|
||||
@ -79,7 +80,7 @@ prefer to add ANSI color codes within the error string in an exception and it wi
|
||||
As with any JavaScript or NodeJS code, avoid doing blocking IO operations. For example, avoid using `fs.readFileSync`, because blocking IO can slow down your elm-pages builds and dev server.
|
||||
|
||||
-}
|
||||
get : String -> Encode.Value -> Decoder b -> DataSource.DataSource Error b
|
||||
get : String -> Encode.Value -> Decoder b -> DataSource.DataSource (Catchable Error) b
|
||||
get portName input decoder =
|
||||
DataSource.Internal.Request.request
|
||||
{ name = "port"
|
||||
@ -93,7 +94,7 @@ get portName input decoder =
|
||||
decoder
|
||||
|> DataSource.Http.expectJson
|
||||
}
|
||||
|> DataSource.onError (\_ -> DataSource.fail Error)
|
||||
|> DataSource.onError (\_ -> DataSource.fail (Exception.Catchable Error "Port Error - TODO better error message"))
|
||||
|
||||
|
||||
{-| -}
|
||||
|
Loading…
Reference in New Issue
Block a user