elm-pages-v3-beta/examples/docs/app/ErrorPage.elm

71 lines
1.2 KiB
Elm
Raw Normal View History

2022-04-05 19:13:55 +03:00
module ErrorPage exposing (ErrorPage(..), Model, Msg, head, init, internalError, notFound, statusCode, update, view)
2022-04-05 19:13:55 +03:00
import Effect exposing (Effect)
import Head
import Html.Styled as Html exposing (Html)
import View exposing (View)
type Msg
= Increment
type alias Model =
{ count : Int
}
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 )
head : ErrorPage -> List Head.Tag
head errorPage =
[]
type ErrorPage
= NotFound
| InternalError String
notFound : ErrorPage
notFound =
NotFound
internalError : String -> ErrorPage
internalError =
InternalError
2022-04-05 19:13:55 +03:00
view : ErrorPage -> Model -> View Msg
view error model =
{ body =
2022-04-05 19:13:55 +03:00
[ Html.div []
[ Html.p [] [ Html.text "Page not found. Maybe try another URL?" ]
]
2022-04-05 19:13:55 +03:00
]
, title = "This is a NotFound Error"
}
statusCode : ErrorPage -> number
statusCode error =
case error of
NotFound ->
404
InternalError _ ->
500