我从正在使用的 API 收到错误响应,但 Google 脚本似乎截断了该消息。如何在 Google 脚本中查看完整消息?
这是消息:
https://api.myintervals.com/task/的请求失败,返回代码 400。截断的服务器响应:{"personid":"180761","status":"错误请求","code":400, "error":{"code":18,"message":"发生验证错误(缺少必需的字段/参数...(使用 muteHttpExceptions 选项检查完整响应)(第 171 行,文件“IntervalsPull”)
muteHttpExceptions
选项来抑制异常并获取作为HTTPResponse返回的错误。
options = {muteHttpExceptions: true};
var response = UrlFetchApp.fetch("https://api.myintervals.com/task/", options);
Logger.log(response.getContentText());
现在查看日志以查看完整的错误响应。
options.muteHttpExceptions = true;
const res = UrlFetchApp.fetch(url, options);
console.log(res.getResponseCode());
console.log(res);
DriveApp
.getFoldersByName('test'/*A folder in Drive*/)
.next()
.createFile(res.getBlob().setName('response'))