From c6d55561bf8422301ea7a2d08b9a7c3e30a1440e Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Sat, 30 Oct 2021 19:24:00 +0300 Subject: Implement authentication --- src/Utils.elm | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/Utils.elm (limited to 'src/Utils.elm') 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 -- cgit v1.3