choonkeat/elm-ext-http/1.1.0

NOTE: the latest version is 2.0.0

Ext.Http

This module extends the Http module with better error handling and more information in the success case.

type Error a
= BadUrl String
| Timeout
| NetworkError
| BadStatus Metadata a
| BadJson Metadata a Error

Use Ext.Http.Error instead of Http.Error to get more information about the error.

type alias TaskInput x a =
{ method : String
, headers : List Header
, url : String
, body : Body
, resolver : Resolver x a
, timeout : Maybe Float
}

Named type alias for the Http.task parameter

errorString : Error String -> String

Convenience function to convert an Ext.Http.Error to a String.

Response a
-> Result
(Error a)
{ meta : Metadata
, data : a
}

A resolver that does process the response at all. It just returns the response as is, but with Http.Metadata included. And with error type as Ext.Http.Error instead of Http.Error.

Useful for decoding non-json payloads like Bytes or String

Decoder a
-> Response String
-> Result
(Error String)
{ meta : Metadata
, data : a
}

Resolver for Http.task that includes proper details in both the error case and metadata in the success case.

Usually metadata is not needed in the success case, just add Task.map .data to your existing code

```diff
 Http.task
     { method = "GET"
     , headers = []
     , url = "https://example.com"
     , body = Http.emptyBody
-    , resolver = Http.stringResolver (otherJsonResolver myDecoder)
+    , resolver = Http.stringResolver (Ext.Http.jsonResolver myDecoder)
     , timeout = Nothing
     }
+    |> Task.map .data
```

But when you need it, having the metadata available is very useful.

```diff
 Http.task
     { method = "GET"
     , headers = []
     , url = "https://example.com"
     , body = Http.emptyBody
     , resolver = Http.stringResolver (Ext.Http.jsonResolver myDecoder)
     , timeout = Nothing
     }
+    |> Task.map (Debug.log "{ meta, data }")
     |> Task.map .data
```