How to customize 404 NotFound handler?

Use the withNotFoundHandler on SharafHandler:

SharafHandler(routes).withNotFoundHandler { req =>
  Response.withBody(MyCustomNotFoundPage)
    .withStatus(StatusCodes.NOT_FOUND)
}

The withNotFoundHandler accepts a Request => Response[?] parameter.
You can use the request if you need to dynamically decide on what to return.
Or ignore it and return a static not found response.