【发布时间】:2019-08-20 21:31:01
【问题描述】:
问题
我的代码正在数据库中搜索记录并在找不到现有条目时返回错误。它需要在解析之前检查请求是否为空,如果没有找到记录则返回一个空数组,如果找到则返回[results]数组。我该如何解决这个问题?
这是用于 Zapier 与 Zoho CRM 的集成,它将通过 Account_Name 搜索自定义模块以查找现有记录,如果不存在则创建一个。
代码
const options = {
url: `https://www.zohoapis.com/crm/v2/Accounts/search?criteria=(Account_Name:equals:${bundle.inputData.Account_Name})`,
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': `Zoho-oauthtoken ${bundle.authData.access_token}`,
'Accept': 'application/json'
},
params: {
}
}
return z.request(options)
.then((response) => {
response.throwForStatus();
const results = [z.JSON.parse(response.content)];
return [results];
});
【问题讨论】:
标签: javascript arrays json error-handling zapier