Custom Error Handling - Axiom

Overview

Most sites you'll build will need to deal with errors and handle them in a user friendly manner. This ranges from Axiom explosions to you assuming that property [x] is not null and calling a function on it to a 404. There are a few ways to handle these kinds of errors in Axiom.

Custom error handling is done by simply defining functions on the AxiomObject prototype:

function notfound() {
return "Weasels ran off with the page you were looking for. Sorry.";
}

function error() {
return "The gnomes are on lunch break. (Ok, so there was an error in application "+app.getName()+")";
}

function unauthorized() {
return "You ain't allowed in here.";
}

Not Found

When you have a 404 from a request you want to handle that inside the application. One way to do this is to have a template to render for 404's. The biggest hurdle with this is that you wont ever be able to call a template or file from this, because the reason you are getting a 404 is that "this" is non-existent. I recommend doing a search for an object you do know exists such as the "HomePage" or some similar object and then rendering the template from that object.

function notfound() {
var hp = app.getHits("HomePage", {}).objects(0,1)[0];
return hp.template({}); //assuming template is representative of the actual file to be rendered.
}