使用 sails框架,将api的错误通过res.serverError 返回给前端,前端在调用api的catch中捕捉。在本地,部署pre环境都是ok,部署production却不能正确 读取数据。
在sails res.serverError api说明 中提示如下:
Notes
#
This method is terminal, meaning that it is generally the last line of code your app should run for a given request (hence the advisory usage of return throughout these docs).
res.serverError() (like other userland response methods) can be overridden or modified. It runs the response method defined in api/responses/serverError.js. If a serverError.js response method does not exist in your app, Sails will use the default behavior.
The specified data 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').
修改:
没有认真查看框架,不知道是否可以通过配置来改这个错误。
只是将 res.serverError 改成 res.ok
这样前端 直接在call 的api中做个判断,读取error即可。