totaljs / framework

Node.js framework
http://www.totaljs.com
Other
4.36k stars 450 forks source link

How to customize error response of F. onAuthorize #693

Closed ckpiggy closed 5 years ago

ckpiggy commented 5 years ago
F.onAuthorize = function (req, res, flags, callback) {

}

When callback(false) the framework will send html with 401. How can I customize the response data to JSON like:

{
    "error": "unauthorized"
}
petersirka commented 5 years ago

Hi @ckpiggy, sorry for delay, here is the solution:


AUTH(function(req, res, flags, callback) {
    callback(false);
});

// And then create a system route:
ROUTE('#401', function() {
    this.json({ error: 'unauthorized' });
});