Error handling

An error handler can be specified using the @onError decorator. The error that was raised is accessible via the Context.error property.

import { controller, get, onError } from 'kikwit';
@onError(errorHandler)
@controller
export class Products {
    @get
    list(context) { 
        const nothing = null;      
        context.send(nothing.toString());
    } 
    @get
    details(context) {     
        const a = null;
        const result = a.startsWith('b');
        context.send('Unreachable');
    } 
}
// The following handler will be called when an exception in raised in list or details actions 
function errorHandler(context) {
    // log context.error
    context.render('niceErrorPage', context.error);
}

results matching ""

    No results matching ""