User Tools

Site Tools


Table of Contents

Controller actions

In Sugoi, you can “throw” actions. It could look weird but it's an good choice, because throwing exceptions actually stops the code execution and usually exits the program.

In the context of a web application, you often want to trigger an error message or a redirection and stop the current action.


//Example : Redirect the user to another page if he's not logged
function doDashboard(){
     throw Redirect("/user/login");


Throwing an Error will display a clean message on the top of the page

//Example : throw an error message if the password does not match
function doLogin(){
  var u =$password == app.params.get("password"));
     throw Error("/login","This password does not match with any of our users");


Same concept, with a confirmation message :

function doRecord(product:db.Product,quantity:Int){
  var order = Order.recordOrder(product, quantity, app.user);
     throw Ok("/home","You order has been recorded.");
     throw Error("/record","Warning, an error occured while processing your order");