bjchy-udg-sdk 1.8.3 → 1.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/package.json +1 -1
- package/src/request.js +2 -0
package/README.md
CHANGED
|
@@ -569,11 +569,13 @@ if (client.now() < new Date(activity.bookEnd)) { /* 可以报名 */ }
|
|
|
569
569
|
|
|
570
570
|
返回兼容微信云开发:`get → {data}`、`count → {total}`、`aggregate → {list}`、`add → {_id}/{ids}`、`set → {_id, stats:{created,updated}}`、`update → {stats:{updated}}`、`remove → {stats:{removed}}`。
|
|
571
571
|
|
|
572
|
-
失败抛统一错误对象:`{ errorCode, errorMessage, requestId, timestamp }
|
|
572
|
+
失败抛统一错误对象:`{ errorCode, errorMessage, errorDetails?, requestId, timestamp }`。`errorDetails` 是可选的结构化诊断,关系库数据错误会包含 `dataSource/collection/field/databaseCode/reason` 及可取得的长度或约束信息;不包含 SQL、原始值、连接信息或堆栈。
|
|
573
|
+
|
|
574
|
+
常见错误码除 `UNSUPPORTED_OPERATOR`、`TENANT_NOT_FOUND`、`DB_NOT_FOUND`、`READONLY_DATABASE`、`APPEND_ONLY_TABLE`、`TABLE_ACCESS_DENIED`、`FORBIDDEN`、`TIMEOUT` 外,还包括:`TYPE_MISMATCH`、`INVALID_NUMBER`、`INVALID_DATE`、`VALUE_TOO_LONG`、`VALUE_OUT_OF_RANGE`、`REQUIRED_FIELD_MISSING`(均为 400),以及 `DUPLICATE_KEY`、`CONSTRAINT_VIOLATION`(409)。可修正的数据错误使用 4xx,确保生产反代不会把详细 JSON 替换为 HTML。
|
|
573
575
|
|
|
574
576
|
## 说明
|
|
575
577
|
|
|
576
|
-
-
|
|
578
|
+
- 日期与关系库类型兼容:SDK 与 Gateway 以 `{ $date: 毫秒 }` 传输 `Date`。关系库按实际列类型保存:日期列保持日期,数字/字符列保存毫秒值;布尔写数字/字符列转 `1/0`;带时区的完整 ISO 8601 或 13 位毫秒时间戳写日期列会转 `Date`。不猜 10 位秒时间戳,不自动 JSON 化对象/数组,不截断或舍入;不存在字段仍严格报错
|
|
577
579
|
- `db.serverDate()` V1 以客户端时间近似;需要可信的“当前时间”用 `client.now()`,需要不可伪造的“写入时间”用 Gateway 的 `beforeWrite.autoTimestamps` 钩子
|
|
578
580
|
- distinct / 文件上传:V1 不提供
|
|
579
581
|
- 集合是首次写入时自动创建的(CloudBase 端也一样,Gateway 会代建并放开集合权限)
|
package/package.json
CHANGED
package/src/request.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* 数据请求自动携带 token;遇 401/403 时自动 refresh → 重试 → 必要时自动重登(业务无感)。
|
|
7
7
|
* 每个响应(成功与失败)都带 Gateway 的 timestamp,据此被动维护本地时钟偏差,供 client.now() 使用。
|
|
8
|
+
* 失败响应若含 errorDetails,UdgRequestError 会原样保留这份不含 SQL/原始值的结构化诊断。
|
|
8
9
|
*/
|
|
9
10
|
const { encode, decode } = require('./serialize')
|
|
10
11
|
|
|
@@ -14,6 +15,7 @@ class UdgRequestError extends Error {
|
|
|
14
15
|
this.name = 'UdgRequestError'
|
|
15
16
|
this.errorCode = (payload && payload.errorCode) || 'NETWORK_ERROR'
|
|
16
17
|
this.errorMessage = this.message
|
|
18
|
+
this.errorDetails = (payload && payload.errorDetails) || null
|
|
17
19
|
this.requestId = (payload && payload.requestId) || ''
|
|
18
20
|
this.timestamp = (payload && payload.timestamp) || new Date().toISOString()
|
|
19
21
|
this.httpStatus = httpStatus || 0
|