gpt4 book ai didi

javascript - 在 lawnchair 回调中接收错误

转载 作者:行者123 更新时间:2023-11-29 14:58:00 27 4
gpt4 key购买 nike

如果我在 lawnchair 中调用一个方法并出错,我可以获得错误回调吗?我正在实现一个适配器,并且有一些已知的错误情况,我想将这些情况提供给客户端进行处理。但我无法找出 API 中返回错误的方式。它们是节点样式吗? eg: callback(error, result) where error=null 在没有错误的情况下,或者其他?

最佳答案

简短回答:Lawnchair 适配器的方法没有进行任何重大错误处理。如果适配器中发生任何特别糟糕的事情,客户端将收到异常。

下面是 DOM 适配器的 save 方法的代码——很明显,如果发生任何不好的事情,回调根本不会被调用;应用程序的代码将不得不处理异常。

save: function (obj, callback) {
var key = obj.key ? this.name + '.' + obj.key : this.name + '.' + this.uuid()
// if the key is not in the index push it on
if (this.indexer.find(key) === false) this.indexer.add(key)
// now we kil the key and use it in the store colleciton
delete obj.key;
storage.setItem(key, JSON.stringify(obj))
obj.key = key.slice(this.name.length + 1)
if (callback) {
this.lambda(callback).call(this, obj)
}
return this
},

当然,您可以在适配器中进行内部错误处理,并将附加参数传递给回调。这样做会使您的适配器的行为与其他适配器不一致,这可能是一个缺点。

我建议您的适配器会像其他适配器一样抛出异常,除非可以从适配器内部的错误中恢复。

关于javascript - 在 lawnchair 回调中接收错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14743649/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com