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:

  1. you can call res.badrequest(), return 400 status response browser.
  2. 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);

  3. 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. calling res.badrequest()) , avoiding overhead of separate service module.

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -