Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.

Error handlers

luizmineo edited this page May 29, 2014 · 4 revisions

The @ErrorHandler annotation is used to define an error handler:

@app.ErrorHandler(HttpStatus.NOT_FOUND)
handleNotFoundError() => app.redirect("/error/not_found.html");

Also, you can define an error handler for a specific URL pattern

@app.ErrorHandler(HttpStatus.NOT_FOUND, urlPattern: r'/public/.+')
handleNotFoundError() => app.redirect("/error/not_found.html");

If you define an error handler inside a group, then the handler will be restricted to the group path.

@app.Group('/user')
class User {

  @app.ErrorHandler(500)
  onInternalServerError() {
    if (app.chain.error is UserException) {
      ...
    } 
  }

  @app.Route('/find')
  find() {
    ...
  }
}

When an error happens, Redstone.dart will invoke the most specific handler for the request.

Clone this wiki locally