【问题标题】:How to resolve an ok 200 error when integrating slack incoming webhook with angular 4.2.4?将 slack 传入 webhook 与 angular 4.2.4 集成时如何解决 ok 200 错误?
【发布时间】:2017-09-20 19:52:31
【问题描述】:

当我单击按钮将消息提交给 slack 时,我会收到以下错误消息。但是,该消息已成功发送到松弛通道。该错误在 subscribe 方法上起作用。我尝试删除 subscribe 方法,但由于 observable 没有它就无法运行,我不得不使用它。

错误信息:

HttpErrorResponse {headers: HttpHeaders, status: 200, statusText: "OK", url: "https://hooks.slack.com/services/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", ok: false, …} .   
error:{error: SyntaxError: Unexpected token o in JSON at position 0 at Object.parse (<anonymous>) at XMLHt…, text: "ok"} .  
headers:HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ} .  
message:"Http failure during parsing for https://hooks.slack.com/services/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" .  
name:"HttpErrorResponse"
ok:false
status:200
statusText:"OK"

Angular4 代码:

const payload = JSON.stringify({"text": "Hihi",});  
  const headers = new HttpHeaders().set('Content-type', 'application/x-www-form-urlencoded; charset=UTF-8');  
  this.http.request(
    'POST',
    "https://hooks.slack.com/services/TOKEN",
    {
      'body': payload,
      'headers': headers,
    }
  ).subscribe();

【问题讨论】:

  • Unexpected token o in JSON - 看来,尽管您尝试将其解析为 JSON,但这并不是您实际得到的。
  • 那我该如何处理呢?请澄清,因为我最近才开始使用 angular4,第一次使用 slack 集成和这个 200 ok 错误。这可能是松弛的服务器错误吗?

标签: angular integration slack-api angular4-httpclient


【解决方案1】:

没关系,我需要做的就是添加一个响应类型。谢谢大家!

【讨论】:

  • 你能证明你是怎么做到的吗@zhu chen,我也遇到了类似的问题,这将非常有帮助
猜你喜欢
  • 2021-08-14
  • 2019-09-17
  • 2018-04-16
  • 1970-01-01
  • 1970-01-01
  • 2015-06-12
  • 1970-01-01
  • 1970-01-01
  • 2021-07-14
相关资源
最近更新 更多