You would like to use a custom status page (4xx or 5xx status pages).


You can set custom error pages by using the errorHandler function in the instance of the App inside the Foundation.hs file. The following code shows two examples:

errorHandler NotFound = fmap toTypedContent $ defaultLayout $ do
  setTitleI MsgTitleNotFound
  $(widgetFile "error/404")

errorHandler err = case err of
  PermissionDenied message ->
    fmap toTypedContent $ defaultLayout $ do
      setTitleI MsgTitleForbidden
      $(widgetFile "error/permission-denied")
  _ ->
    fmap toTypedContent $ defaultLayout $ do
      setTitleI MsgTitleError
      $(widgetFile "error/other")


As you can see, we used the errorHandler function in three different ways. The first definition matches the incoming error directly for a NotFound error. The following examples accept any other error and match explicitly (So we don't need to repeat the function name in our code). Our match just takes into account the PermissionDenied error and defines a custom layout/design for all other errors.

As well we just assumed that the templates error/404, error/permission-denied and error/other already exist. Before using the code you will need to create the folder error in the templates folder with the according files inside. If you defined any custom layouts before, you can as well replace defaultLayout in the function to have a different layout for your custom error pages.