2022-03-31 20:46:39 +03:00
|
|
|
module ErrorPage exposing (ErrorPage(..), Model, Msg, head, init, internalError, notFound, statusCode, update, view)
|
2022-03-29 21:48:04 +03:00
|
|
|
|
2022-03-31 20:46:39 +03:00
|
|
|
import Effect exposing (Effect)
|
2022-03-31 19:04:11 +03:00
|
|
|
import Head
|
2022-03-29 21:48:04 +03:00
|
|
|
import Html exposing (Html)
|
2022-03-31 20:46:39 +03:00
|
|
|
import Html.Events exposing (onClick)
|
2022-03-31 21:01:47 +03:00
|
|
|
import Route
|
2022-03-31 19:04:11 +03:00
|
|
|
import View exposing (View)
|
|
|
|
|
|
|
|
|
2022-03-31 20:46:39 +03:00
|
|
|
type Msg
|
|
|
|
= Increment
|
|
|
|
|
|
|
|
|
2022-03-31 19:04:11 +03:00
|
|
|
type alias Model =
|
2022-03-31 20:46:39 +03:00
|
|
|
{ count : Int
|
|
|
|
}
|
2022-03-31 19:04:11 +03:00
|
|
|
|
|
|
|
|
2022-03-31 20:46:39 +03:00
|
|
|
init : ErrorPage -> ( Model, Effect Msg )
|
|
|
|
init errorPage =
|
|
|
|
( { count = 0 }
|
|
|
|
, Effect.none
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
update : ErrorPage -> Msg -> Model -> ( Model, Effect Msg )
|
|
|
|
update errorPage msg model =
|
|
|
|
case msg of
|
|
|
|
Increment ->
|
|
|
|
( { model | count = model.count + 1 }, Effect.none )
|
2022-03-31 19:04:11 +03:00
|
|
|
|
|
|
|
|
|
|
|
head : ErrorPage -> List Head.Tag
|
|
|
|
head errorPage =
|
|
|
|
[]
|
2022-03-29 21:48:04 +03:00
|
|
|
|
|
|
|
|
|
|
|
type ErrorPage
|
|
|
|
= NotFound
|
2022-03-31 21:01:47 +03:00
|
|
|
| InvalidPokedexNumber String
|
|
|
|
| MissingPokedexNumber Int
|
2022-03-29 21:48:04 +03:00
|
|
|
| InternalError String
|
|
|
|
|
|
|
|
|
|
|
|
notFound : ErrorPage
|
|
|
|
notFound =
|
|
|
|
NotFound
|
|
|
|
|
|
|
|
|
|
|
|
internalError : String -> ErrorPage
|
|
|
|
internalError =
|
|
|
|
InternalError
|
|
|
|
|
|
|
|
|
2022-03-31 20:46:39 +03:00
|
|
|
view : ErrorPage -> Model -> View Msg
|
|
|
|
view error model =
|
2022-03-31 21:01:47 +03:00
|
|
|
case error of
|
|
|
|
InvalidPokedexNumber invalidNumber ->
|
|
|
|
{ body =
|
|
|
|
[ Html.div []
|
|
|
|
[ Html.p []
|
|
|
|
[ Html.text ("`" ++ invalidNumber ++ "`" ++ " doesn't look like a pokedex number. Make sure it's a valid number, like ")
|
|
|
|
, Route.PokedexNumber_ { pokedexNumber = "25" } |> Route.link [] [ Html.text "25" ]
|
|
|
|
, Html.text "."
|
|
|
|
]
|
|
|
|
, Html.div []
|
|
|
|
[ Html.button
|
|
|
|
[ onClick Increment
|
|
|
|
]
|
|
|
|
[ Html.text
|
|
|
|
(model.count
|
|
|
|
|> String.fromInt
|
|
|
|
)
|
|
|
|
]
|
|
|
|
]
|
2022-03-31 20:46:39 +03:00
|
|
|
]
|
2022-03-31 21:01:47 +03:00
|
|
|
]
|
|
|
|
, title = "Invalid pokedex number"
|
|
|
|
}
|
|
|
|
|
|
|
|
MissingPokedexNumber missingNumber ->
|
|
|
|
{ body =
|
|
|
|
[ Html.div []
|
|
|
|
[ Html.p []
|
|
|
|
[ Html.text ("`" ++ String.fromInt missingNumber ++ "`" ++ " isn't in our pokedex. This pokemon is pretty cute, though: ")
|
|
|
|
, Route.PokedexNumber_ { pokedexNumber = "25" } |> Route.link [] [ Html.text "#25" ]
|
|
|
|
, Html.text "."
|
|
|
|
]
|
|
|
|
, Html.div []
|
|
|
|
[ Html.button
|
|
|
|
[ onClick Increment
|
|
|
|
]
|
|
|
|
[ Html.text
|
|
|
|
(model.count
|
|
|
|
|> String.fromInt
|
|
|
|
)
|
|
|
|
]
|
|
|
|
]
|
2022-03-31 20:46:39 +03:00
|
|
|
]
|
|
|
|
]
|
2022-03-31 21:01:47 +03:00
|
|
|
, title = "Invalid pokedex number"
|
|
|
|
}
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
{ body =
|
|
|
|
[ Html.div []
|
|
|
|
[ Html.p [] [ Html.text "Page not found. Maybe try another URL?" ]
|
|
|
|
, Html.div []
|
|
|
|
[ Html.button
|
|
|
|
[ onClick Increment
|
|
|
|
]
|
|
|
|
[ Html.text
|
|
|
|
(model.count
|
|
|
|
|> String.fromInt
|
|
|
|
)
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
, title = "This is a NotFound Error"
|
|
|
|
}
|
2022-03-29 21:48:04 +03:00
|
|
|
|
|
|
|
|
|
|
|
statusCode : ErrorPage -> number
|
|
|
|
statusCode error =
|
|
|
|
case error of
|
|
|
|
NotFound ->
|
|
|
|
404
|
|
|
|
|
|
|
|
InternalError _ ->
|
|
|
|
500
|
2022-03-31 21:01:47 +03:00
|
|
|
|
|
|
|
InvalidPokedexNumber _ ->
|
|
|
|
400
|
|
|
|
|
|
|
|
MissingPokedexNumber _ ->
|
|
|
|
404
|