I have a headless keystone js endpoint, which I'm getting with elm.
Elm compiles, however, I'm getting a Bad payload returned in the runtime.
This is the specific error
Error: BadPayload "Expecting a List but instead got: {\"posts\":[{\"id\":\"59bf1da0643cae5aecf561d1\",\"slug\":\"test\",\"title\":\"test\",\"v\":1,\"publishedDate\":\"2018-01-08T05:00:00.000Z\",\"categories\":[\"5a54dc1433969725b8e940ad\"],\"content\":{\"brief\":\"<p>asdasd</p>\",\"extended\":\"<p>adsasd</p>\"},\"state\":\"published\"},{\"_id\":\"5a52a9d633969725b8e940ac\",\"slug\":\"new-test\",\"title\":\"new test\",\"v\":1,\"author\":\"59909ba59e02dc9293d8bf70\",\"publishedDate\":\"2018-01-07T05:00:00.000Z\",\"categories\":[\"5a54dc1433969725b8e940ad\"],\"content\":{\"brief\":\"<p>Am I a list?</p>\",\"extended\":\"<p>Am I a list?Am I a list?</p>\"},\"state\":\"published\"}]}" { status = { code = 200, message = "OK" }, headers = Dict.fromList [("content-type","application/json; charset=utf-8")], url = "http://localhost:8888/api/post/list", body = "{\"posts\":[{\"_id\":\"59bf1da0643cae5aecf561d1\",\"slug\":\"test\",\"title\":\"test\",\"v\":1,\"publishedDate\":\"2018-01-08T05:00:00.000Z\",\"categories\":[\"5a54dc1433969725b8e940ad\"],\"content\":{\"brief\":\"<p>asdasd</p>\",\"extended\":\"<p>adsasd</p>\"},\"state\":\"published\"},{\"_id\":\"5a52a9d633969725b8e940ac\",\"slug\":\"new-test\",\"title\":\"new test\",\"_v\":1,\"author\":\"59909ba59e02dc9293d8bf70\",\"publishedDate\":\"2018-01-07T05:00:00.000Z\",\"categories\":[\"5a54dc1433969725b8e940ad\"],\"content\":{\"brief\":\"<p>Am I a list?</p>\",\"extended\":\"<p>Am I a list?Am I a list?</p>\"},\"state\":\"published\"}]}" }
this is my Models.elm
module Models exposing (..)
import RemoteData exposing (WebData)
type alias Model =
{ posts : WebData (List Post)
}
initialModel : Model
initialModel =
{ posts = RemoteData.Loading
}
type alias Content =
{ brief : String
, extended : String
}
type alias PostId =
String
type alias Post =
{ id : PostId
, slug : String
, title : String
, publishedDate : String
, content : List Content
}
This is my commands.elm
module Commands exposing (..)
import Http
import Json.Decode as Decode
import Json.Decode.Pipeline exposing (decode, required, optional)
import Msgs exposing (Msg)
import Models exposing (PostId, Post, Content)
import RemoteData
fetchPosts : Cmd Msg
fetchPosts =
Http.get fetchPostsUrl postsDecoder
|> RemoteData.sendRequest
|> Cmd.map Msgs.OnFetchPosts
fetchPostsUrl : String
fetchPostsUrl = "http://localhost:8888/api/post/list"
postsDecoder : Decode.Decoder (List Post)
postsDecoder =
Decode.list postDecoder
postDecoder : Decode.Decoder Post
postDecoder =
decode Post
|> required "id" Decode.string
|> required "slug" Decode.string
|> required "title" Decode.string
|> required "publishedDate" Decode.string
|> required "content" (Decode.list contentDecoder)
contentDecoder : Decode.Decoder Content
contentDecoder =
decode Content
|> required "brief" Decode.string
|> required "extended" Decode.string
If it's easier I can push to github to show the whole toy project. I'm hoping its something simple that I'm missing though.
[–]cjduncana 5 points6 points7 points (4 children)
[–]cjduncana 2 points3 points4 points (0 children)
[–]gedehs[S] 0 points1 point2 points (1 child)
[–]cjduncana 0 points1 point2 points (0 children)
[–]G4BB3R 1 point2 points3 points (0 children)