diff options
| author | Jan Tuomi <jan.tuomi@valuemotive.com> | 2021-10-30 19:24:00 +0300 |
|---|---|---|
| committer | Jan Tuomi <jan.tuomi@valuemotive.com> | 2021-10-30 19:29:03 +0300 |
| commit | c6d55561bf8422301ea7a2d08b9a7c3e30a1440e (patch) | |
| tree | 33fd6b0c1150b67e2f8ba38806a984c3cecccc75 /src/Utils.elm | |
| parent | e24ba80820bd49af72a9e1702ed635e9b63452d1 (diff) | |
Implement authentication
Diffstat (limited to 'src/Utils.elm')
| -rw-r--r-- | src/Utils.elm | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/Utils.elm b/src/Utils.elm new file mode 100644 index 0000000..3da2c74 --- /dev/null +++ b/src/Utils.elm @@ -0,0 +1,42 @@ +module Utils exposing (..) + +import Http + + + +-- UTILS + + +httpErrorToString : Http.Error -> String +httpErrorToString err = + case err of + Http.BadUrl url -> + "URL {0} is invalid" |> templ [ url ] + + Http.Timeout -> + "Request has timed out" + + Http.NetworkError -> + "Unable to reach the server, check your network connection" + + Http.BadStatus status -> + "Server responded with status {0}" |> templ [ String.fromInt status ] + + Http.BadBody msg -> + msg + + +templ : List String -> String -> String +templ rs original = + let + templElement_ : ( Int, String ) -> String -> String + templElement_ ( index, r ) orig_ = + String.replace (String.replace "n" (String.fromInt index) "{n}") r orig_ + in + List.indexedMap Tuple.pair rs + |> List.foldl templElement_ original + + +listFlat : List (List a) -> List a +listFlat ll = + List.foldl (\acc l -> l ++ acc) [] ll |
