使用nodejs框架sails,本地和pre-prodcution环境都是正确,但是生产错误

使用 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即可。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,你的第一个问题是关于 node.js 和 MySQL 插入语句的语法错误提示,是吗? 首先,你需要确保你的 MySQL 语句的语法是正确的。MySQL 插入语句的基本语法如下: ``` INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...); ``` 其中,`table_name` 是你要插入数据的表的名称,`column1, column2, column3` 是你要插入的列的名称,`value1, value2, value3` 是你要插入的值。 在 node.js 中,你可以使用 `mysql` 模块来连接和操作 MySQL 数据库。下面是一个示例代码,演示如何使用 `mysql` 模块来插入数据到 MySQL 数据库中: ```javascript const mysql = require('mysql'); const connection = mysql.createConnection({ host: 'localhost', user: 'root', password: 'password', database: 'mydatabase' }); connection.connect((err) => { if (err) throw err; console.log('Connected!'); const sql = "INSERT INTO customers (name, address) VALUES ('John Doe', 'Highway 71')"; connection.query(sql, (err, result) => { if (err) throw err; console.log('1 record inserted'); connection.end(); }); }); ``` 在上面的代码中,我们创建了一个 `mysql` 连接对象 `connection`,并在连接成功后,使用 `connection.query()` 方法来执行 MySQL 插入语句。 如果你使用类似上面的代码来执行 MySQL 插入语句,但是仍然遇到语法错误提示,那么你需要检查你的 MySQL 语句是否正确。你可以尝试在 MySQL 命令行中执行你的 MySQL 语句,以确保它没有语法错误
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值