sails.js - Bind a controller to handle bad request in sails js -
i'm new sails js , still exploring framework. question that, can bind action inside controller whenever there bad request front end? rather calling in response page, customized controller instead called.
please shed light. thanks
you have few options:
- you can call
res.badrequest()
, return 400 status response browser. you can create service house custom "bad request" response code, , call controller. example, make api/services/responseservice.js file method like:
badrequest: function(req, res) { return res.send(400, "you've been bad!"); }
and call controller
responseservice.badrequest(req, res);
- if you're using sails v0.10.x, can customize default
badrequest
response modifying api/responses/badrequest.js. has benefits of #2, while allowing use semantics of #1 (i.e. callingres.badrequest()
) , avoiding overhead of separate service module.
Comments
Post a Comment