onasty/web/src/Api.elm (view raw)
Olexandr Smirnov
Olexandr Smirnov
ss2316544@gmail.com web: prompt non verified user to activate their account on sing in (#160)..., 11 months ago
ss2316544@gmail.com web: prompt non verified user to activate their account on sing in (#160)..., 11 months ago
| 1 | module Api exposing (Error(..), Response(..), errorMessage, is404, isNotVerified) |
| 2 | |
| 3 | import Http |
| 4 | import Json.Decode |
| 5 | |
| 6 | |
| 7 | type Error |
| 8 | = HttpError |
| 9 | { message : String |
| 10 | , reason : Http.Error |
| 11 | } |
| 12 | | JsonDecodeError |
| 13 | { message : String |
| 14 | , reason : Json.Decode.Error |
| 15 | } |
| 16 | |
| 17 | |
| 18 | type Response value |
| 19 | = Loading |
| 20 | | Success value |
| 21 | | Failure Error |
| 22 | |
| 23 | |
| 24 | errorMessage : Error -> String |
| 25 | errorMessage error = |
| 26 | case error of |
| 27 | HttpError err -> |
| 28 | err.message |
| 29 | |
| 30 | JsonDecodeError err -> |
| 31 | err.message |
| 32 | |
| 33 | |
| 34 | is404 : Error -> Bool |
| 35 | is404 error = |
| 36 | case error of |
| 37 | HttpError { reason } -> |
| 38 | reason == Http.BadStatus 404 |
| 39 | |
| 40 | _ -> |
| 41 | False |
| 42 | |
| 43 | |
| 44 | isNotVerified : Error -> Bool |
| 45 | isNotVerified error = |
| 46 | case error of |
| 47 | HttpError { reason, message } -> |
| 48 | (reason == Http.BadStatus 400) && String.contains "user is not activated" message |
| 49 | |
| 50 | _ -> |
| 51 | False |