Giter Site home page Giter Site logo

Comments (7)

sdjcw avatar sdjcw commented on June 7, 2024

云引擎移除 domain 的使用吧。
失败和出现异常都可以归为 不成功,感觉没什么问题。

from leanengine-node-sdk.

jysperm avatar jysperm commented on June 7, 2024

打算这样来做,继续兼容老的云函数定义方法,但如果传递给 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.

jysperm avatar jysperm commented on June 7, 2024

@aisk @leeyeh

from leanengine-node-sdk.

leeyeh avatar leeyeh commented on June 7, 2024

使用参数长度作为区分的做法并不优雅。之前使用 response.success/response.fail 的方式会存在多次调用、我们无法感知结果等问题,因此 Promise 应该是理想的方案。所以我觉得我们应该优先 Promise 的支持,然后尽可能兼容之前 response 的用法(并且应该标记为废弃)。而不是「兼容 Promise」。

from leanengine-node-sdk.

jysperm avatar jysperm commented on June 7, 2024

或者你可以说默认启用 Promise 模式,当参数数量是两个的时候再兼容 response.success/error。

from leanengine-node-sdk.

leeyeh avatar leeyeh commented on June 7, 2024

LGTM

from leanengine-node-sdk.

jysperm avatar jysperm commented on June 7, 2024

已在 #102 实现

from leanengine-node-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.