diff --git a/README.markdown b/README.markdown index 220031db75..a2e2f170cf 100644 --- a/README.markdown +++ b/README.markdown @@ -129,12 +129,24 @@ object App { render.plain("we never make it here").toFuture } + /** + * Custom Error Handling with custom Exception + * + * curl http://localhost:7070/unautorized + */ + class Unauthorized extends Exception + + get("/unauthorized") { request => + throw new Unauthorized + } + error { request => request.error match { case Some(e:ArithmeticException) => render.status(500).plain("whoops, divide by zero!").toFuture + case Some(e:Unauthorized) => + render.status(401).plain("Not Authorized!").toFuture case _ => - println(request.error) render.status(500).plain("Something went wrong!").toFuture } }