【问题标题】:How can I see the full server response for this API error message in Google Scripts?如何在 Google Scripts 中查看此 API 错误消息的完整服务器响应?
【发布时间】:2016-12-26 10:49:45
【问题描述】:

我从正在使用的 API 收到错误响应,但 Google 脚本似乎截断了该消息。如何在 Google 脚本中查看完整消息?

这是消息:

https://api.myintervals.com/task/ 的请求失败,返回代码 400。截断的服务器响应:{"personid":"180761","status":"Bad Request","code":400,"error":{"code": 18,"message":"发生验证错误(缺少必填字段/参数...(使用 muteHttpExceptions 选项检查完整响应)(第 171 行,文件“IntervalsPull”)

【问题讨论】:

  • 尝试将 muteHttpExceptions 选项设置为 true。
  • 我该怎么做 - 我是否将其添加到 API 调用的标头中?
  • [developers.google.com/apps-script/reference/url-fetch/… page) 有一个很好的例子。上面写着 `var options = { "method" : "post", "payload" : payload };` 你将添加 muteHttpExceptions : true。
  • 完美,效果很好。谢谢

标签: javascript google-apps-script


【解决方案1】:

正如@DrSatan1 在注释中指出的那样,在参数中传递muteHttpExceptions 选项以抑制异常并将错误返回为HTTPResponse。

options = {muteHttpExceptions: true};
var response = UrlFetchApp.fetch("https://api.myintervals.com/task/", options);
Logger.log(response.getContentText()); 

现在查看您的日志以查看完整的错误响应。

【讨论】:

    猜你喜欢
    • 2020-08-18
    • 1970-01-01
    • 1970-01-01
    • 2016-03-12
    • 2020-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-08
    相关资源
    最近更新 更多