Send a 500 ("Server Error") response back down to the client indicating that some kind of server error occurred (i.e. the error is not the requesting user agent's fault).
return res.serverError();
Or:
return res.serverError(data);return res.serverError(data, pathToView);Like the other built-in custom response modules, the behavior of this method is customizable.
By default, it works as follows:
data as JSON. If no data is provided a default response body will be sent (the string "Server Error").pathToView was provided, Sails will attempt to use that view.pathToView was not provided, Sails will serve a default error page (the view located at views/500.ejs). If that view does not exist, Sails will just send JSON.data argument will be accessible as a view local: data.Using the default error view:
return res.serverError('Salesforce could not be reached');
With a custom view:
return res.serverError(
'Salesforce could not be reached',
'salesforce/leads/edit'
);
- This method is terminal, meaning it is generally the last line of code your app should run for a given request (hence the advisory usage of
returnthroughout these docs).res.serverError()(like other userland response methods) can be overridden or modified. It runs the response method defined in/responses/serverError.js, which is bundled automatically in newly generated Sails apps. If aserverError.jsresponse method does not exist in your app, Sails will implicitly use the default behavior.- If
pathToViewrefers to a missing view, this method will respond as if the request "wants JSON". +By default, the specified error (err) will be excluded from the JSON response and view locals if the app is running in the "production" environment (i.e.process.env.NODE_ENV === 'production').