I am building my first web application in Elm and I have this problem: when I receive a request to the local server, Elm says that it is a "NetworkError", although the browser console says that it worked.
I made a minimal example as follows:
Server created using Haskell and Scotty :
{-
module Main where
import Web.Scotty
import Data.Text.Lazy (pack)
main :: IO ()
main = scotty 3000 $ get "/" $ text $ pack "a"
Everything that he does is answered with the letter “a” when you receive a request to localhost: 3000. The Elm application simply displays the answer, if there is one, and an error if there is one and a button for a request to receive with:
import Http exposing (getString, send, Error)
import Html exposing (Html, text, br, button, body, program)
import Html.Events exposing (onClick)
type Msg
= DataRequest (Result Error String)
| Refresh
type alias Model =
{ response : String
, err : String
}
main : Program Never Model Msg
main = program
{ init = init
, view = view
, update = update
, subscriptions = subscriptions
}
subscriptions : Model -> Sub Msg
subscriptions _ = Sub.none
init : (Model, Cmd Msg)
init = ({ response = "", err = ""} , Cmd.none)
update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
case msg of
DataRequest (Err err) -> ({ model | err = toString err}, Cmd.none)
DataRequest (Ok response) -> ({model | response = response}, Cmd.none)
Refresh -> (model, send DataRequest (getString "http://localhost:3000"))
view : Model -> Html Msg
view {response, err} =
body []
[ text <| "Response: " ++ response
, br [] []
, text <| "Error: " ++ err
, br [] []
, button [ onClick Refresh ] [ text "Send request" ]
]
Here is a screenshot of the browser console when I receive the request. I'm not very good at it, but as I understand it, it looks great.

, "" "" , "" - . "" "NetworkError" "Response" .
Git, - , , :
https://github.com/8n8/elmnetworkerror
( , Elm http request NetworkError , , , .)