mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-27 21:29:55 +03:00
Fix jsonError api route.
This commit is contained in:
parent
3aae8c1adf
commit
78ee8d0117
@ -33,25 +33,32 @@ routes getStaticRoutes htmlToString =
|
||||
]
|
||||
|
||||
|
||||
jsonError : Server.Request.ServerRequest ServerResponse.ServerResponse
|
||||
jsonError : ApiRoute ApiRoute.Response
|
||||
jsonError =
|
||||
Server.Request.oneOf
|
||||
[ Server.Request.jsonBodyResult (Decode.field "name" Decode.string)
|
||||
|> Server.Request.map
|
||||
(\result ->
|
||||
case result of
|
||||
Ok firstName ->
|
||||
ServerResponse.stringBody
|
||||
("Hello " ++ firstName)
|
||||
ApiRoute.succeed
|
||||
(Server.Request.oneOf
|
||||
[ Server.Request.jsonBodyResult (Decode.field "name" Decode.string)
|
||||
|> Server.Request.map
|
||||
(\result ->
|
||||
case result of
|
||||
Ok firstName ->
|
||||
ServerResponse.stringBody
|
||||
("Hello " ++ firstName)
|
||||
|
||||
Err decodeError ->
|
||||
decodeError
|
||||
|> Json.Decode.errorToString
|
||||
|> ServerResponse.stringBody
|
||||
|> ServerResponse.withStatusCode 400
|
||||
)
|
||||
, Server.Request.succeed (ServerResponse.stringBody "Hello anonymous!")
|
||||
]
|
||||
Err decodeError ->
|
||||
decodeError
|
||||
|> Json.Decode.errorToString
|
||||
|> ServerResponse.stringBody
|
||||
|> ServerResponse.withStatusCode 400
|
||||
)
|
||||
, Server.Request.succeed (ServerResponse.stringBody "Hello anonymous!")
|
||||
]
|
||||
|> Server.Request.map DataSource.succeed
|
||||
)
|
||||
|> ApiRoute.literal "api"
|
||||
|> ApiRoute.slash
|
||||
|> ApiRoute.literal "validate-json"
|
||||
|> ApiRoute.serverRender
|
||||
|
||||
|
||||
greet : ApiRoute ApiRoute.Response
|
||||
|
Loading…
Reference in New Issue
Block a user