1

As soon as I click the button to submit the message to slack, I receive the following error message. The message is however successfully sent to the slack channel. The error comes into play upon the subscribe method. I tried removing the subscribe method, but since observable can't run without it, I had to use it.

Error Message:

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 Code:

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();
BSMP
  • 4,596
  • 8
  • 33
  • 44
zhu chen
  • 215
  • 2
  • 11
  • `Unexpected token o in JSON` - it appears that, although you're trying to parse it as JSON, that's not what you're actually getting. – jonrsharpe Sep 20 '17 at 19:55
  • Then how should I approach this? Please clarify because I have only recently started using angular4, and first timer on slack integration and this 200 ok error. Could this be a server error with slack? – zhu chen Sep 20 '17 at 20:00

1 Answers1

-3

Nevermind, all I needed to do was to add in a responsetype. Thanks All!

zhu chen
  • 215
  • 2
  • 11