mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-28 23:12:22 +03:00
Add Request.fromResult helper.
This commit is contained in:
parent
ee345a8359
commit
6633e16a4d
@ -1,7 +1,7 @@
|
||||
module Server.Request exposing
|
||||
( Request(..)
|
||||
, Method(..), methodToString
|
||||
, succeed
|
||||
, succeed, fromResult
|
||||
, requestTime, optionalHeader, expectContentType, expectJsonBody, jsonBodyResult
|
||||
, acceptMethod, acceptContentTypes
|
||||
, map, map2, oneOf, andMap, andThen
|
||||
@ -20,7 +20,7 @@ module Server.Request exposing
|
||||
|
||||
@docs Method, methodToString
|
||||
|
||||
@docs succeed
|
||||
@docs succeed, fromResult
|
||||
|
||||
@docs requestTime, optionalHeader, expectContentType, expectJsonBody, jsonBodyResult
|
||||
|
||||
@ -310,6 +310,19 @@ optionalField fieldName decoder_ =
|
||||
|> Json.Decode.andThen finishDecoding
|
||||
|
||||
|
||||
{-| Turn a Result into a Request. Useful with `andThen`. Turns `Err` into a skipped request handler (non-matching request),
|
||||
and `Ok` values into a `succeed` (matching request).
|
||||
-}
|
||||
fromResult : Result String value -> Request value
|
||||
fromResult result =
|
||||
case result of
|
||||
Ok okValue ->
|
||||
succeed okValue
|
||||
|
||||
Err error ->
|
||||
skipMatch (ValidationError error)
|
||||
|
||||
|
||||
jsonFromResult : Result String value -> Json.Decode.Decoder value
|
||||
jsonFromResult result =
|
||||
case result of
|
||||
|
Loading…
Reference in New Issue
Block a user