IHP Api Reference
Safe HaskellSafe-Inferred

IHP.Controller.NotFound

Synopsis

Documentation

notFoundWhen :: (?context :: ControllerContext) => Bool -> IO () Source #

Stops the action execution with a not found message (404) when the access condition is True.

Example: Checking a user is the author of a blog post.

action EditPostAction { postId } = do
    post <- fetch postId
    notFoundWhen (post.authorId /= currentUserId)

    renderHtml EditView { .. }

This will throw an error and prevent the view from being rendered when the current user is not the author of the post.

notFoundUnless :: (?context :: ControllerContext) => Bool -> IO () Source #

Stops the action execution with a not found message (404) when the access condition is False.

Example: Checking a user is the author of a blog post.

action EditPostAction { postId } = do
    post <- fetch postId
    notFoundUnless (post.authorId == currentUserId)

    renderHtml EditView { .. }

This will throw an error and prevent the view from being rendered when the current user is not the author of the post.

handleNotFound :: Request -> Respond -> IO ResponseReceived Source #

Renders a 404 not found response. If a static/404.html exists, that is rendered instead of the IHP not found page

renderNotFound :: (?context :: ControllerContext) => IO () Source #

Renders an "Not found" page.

This can be useful e.g. when an entity cannot be accessed:

action ExampleAction = do
    renderNotFound

You can override the default access denied page by creating a new file at static/403.html. Then IHP will render that HTML file instead of displaying the default IHP access denied page.