Comments (7)
云引擎移除 domain 的使用吧。
失败和出现异常都可以归为 不成功,感觉没什么问题。
from leanengine-node-sdk.
打算这样来做,继续兼容老的云函数定义方法,但如果传递给 AV.Cloud.define 的函数定义只有一个参数,就启用 Promise 模式:
AV.Cloud.define(function(request) {
return new AV.Query('Post').find().then( posts => {
if (posts.length > 0) {
return posts[0];
} else {
throw new AV.Cloud.Error('posts is empty');
}
});
});
包括 AV.Cloud.beforeSave 等 Hook 也是这样,至于 after 类的 Hook 本来就是一个参数,但也没关系,因为 after 类的 Hook 本来也不关心响应。
Promise 模式下用 Promise 的值作为云函数的响应,如果 Promise 中抛了使用 AV.Cloud.Error 构造的异常,则作为错误返回给客户端(默认 status=400,code=1),AV.Cloud.Error 提供第二个参数来设置 status 和 code AV.Cloud.Error('posts is empty', {status: 422, code: 422})
;如果 Promise 中抛了其他异常则视作服务器端错误,返回 500 响应并打印错误到标准输出。
from leanengine-node-sdk.
from leanengine-node-sdk.
使用参数长度作为区分的做法并不优雅。之前使用 response.success
/response.fail
的方式会存在多次调用、我们无法感知结果等问题,因此 Promise 应该是理想的方案。所以我觉得我们应该优先 Promise 的支持,然后尽可能兼容之前 response 的用法(并且应该标记为废弃)。而不是「兼容 Promise」。
from leanengine-node-sdk.
或者你可以说默认启用 Promise 模式,当参数数量是两个的时候再兼容 response.success/error。
from leanengine-node-sdk.
LGTM
from leanengine-node-sdk.
已在 #102 实现
from leanengine-node-sdk.
Related Issues (20)
- Node SDK 2.0 计划 HOT 7
- 支持async await 吗? HOT 4
- 对实例异常退出的情况增加告警邮件 HOT 1
- 调用本地云函数,返回的 Promise 一直处于 pending 状态 HOT 2
- 检查将 Node SDK 作为客户端使用时的 currentUser
- 我们的 Bug 给用户清晰的「请升级 SDK」提示 HOT 1
- web 实例图表里有不合适的数据 HOT 2
- 如何调用已经部署的云函数? HOT 1
- 升级云引擎 demo 的中间件到 v2.x 以上 HOT 1
- sdk调用云函数本地报错getSessionToken is not a function HOT 2
- 预备环境休眠报错提示为错误的 503 HOT 5
- AV.User.current() 不返回 null HOT 1
- Promise 写法的 beforeHook 没有正确地对 object 进行序列化 HOT 1
- AV.File not saving base64 HOT 5
- Node SDK 4.0 计划 HOT 3
- 在 RPC 请求中,没有正确地序列化数组中的非 Object 值 HOT 1
- 云引擎中设置 serverUrl 不起作用 HOT 2
- 云函数的 request object 提供更具体的类型
- CookieSessionOptions 缺少 maxAge 定义
- TypeScript Declaration File HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from leanengine-node-sdk.