SReject / JSON-For-Mirc

JSON parser for mIRC
19 stars 6 forks source link

Successful DELETE still throws error #11

Closed Dissgruntled closed 8 years ago

Dissgruntled commented 8 years ago

Using this code:

alias unfollowchan {
  var %json followdel
  JSONOpen -duw %json https://api.twitch.tv/kraken/users/ $+ $lower($me) $+ /follows/channels/ $+ $lower($1)
  JSONUrlMethod %json DELETE
  JSONUrlHeader %json Connection close
  JSONUrlHeader %json Accept application/vnd.twitchtv.v3+json
  JSONUrlHeader %json Authorization OAuth $oauth
  JSONUrlGet %json
  if ($jsonerror) echo -s $json(%json).error
}

the object is successfully deleted but still gives the error

Unable to Parse: Invalid JSON

SReject commented 8 years ago

What does this echo

alias unfollowchan {
  var %json followdel
  JSONOpen -duw %json https://api.twitch.tv/kraken/users/ $+ $lower($me) $+ /follows/channels/ $+ $lower($1)
  JSONUrlMethod %json DELETE
  JSONUrlHeader %json Connection close
  JSONUrlHeader %json Accept application/vnd.twitchtv.v3+json
  JSONUrlHeader %json Authorization OAuth $oauth
  JSONUrlGet %json
  if ($jsonerror) {
    echo -s $json(%json).error

    var %get = response.responseText.substring(0,3500)
    echo -s >> $com(JSONHandler::followdel, eval, 1, bstr, %get) >> $replace($com(JSONHandler::followdel).result, $cr, \r, $lf, \n, $chr(32), \s)
  }
}
Dissgruntled commented 8 years ago

Unable to Parse: Invalid JSON (double arrow) 1 >>

SReject commented 8 years ago

Could you run this test:

alias unfollowchan {
  var %json followdel
  JSONOpen -duw %json https://api.twitch.tv/kraken/users/ $+ $lower($me) $+ /follows/channels/ $+ $lower($1)
  JSONUrlMethod %json DELETE
  JSONUrlHeader %json Connection close
  JSONUrlHeader %json Accept application/vnd.twitchtv.v3+json
  JSONUrlHeader %json Authorization OAuth $oauth
  JSONUrlGet %json
  if ($jsonerror) {
    echo -s $json(%json).error

    var %get = response.responseText.length
    echo -s Call: $com(JSONHandler::followdel, eval, 1, bstr, %get) -- Length: $com(JSONHandler::followdel).result

    var %get = response.responseText.substring(0,3500)
    echo -s Call: $com(JSONHandler::followdel, eval, 1, bstr, %get) -- Text: $replace($com(JSONHandler::followdel).result, $cr, \r, $lf, \n, $chr(32), \s)
  }
}
Dissgruntled commented 8 years ago
Unable to Parse: Invalid JSON
Call: 1 -- Length: 0
Call: 1 -- Text:
SReject commented 8 years ago

Mkay. The issue is that twitch is returning invalid JSON in the aspect that it is not returning anything. The JSON parser can't parse data that doesn't exist. For this use-case you can ignore this specific error by using:

if ($json(%json).error && $v1 !=== Unable to Parse: Invalid JSON) {
    ;; an error occurred but it wasn't due to empty JSON
}

As per the JSON standard raising an error for no data is the correct handling. You can test this with your browser's dev console by entering the following line:

JSON.parse("")

Dissgruntled commented 8 years ago

Ok. This is from the twitch API:

Example Response

204 No Content if successful.

The error was no big deal to me, just wanted to let you know.

SReject commented 8 years ago

I do appreciate it.

In the future there's links on the main page of this project for realtime chat that may be a better place for this sort of discussion. (Gitter which is tied directly into github and uses your webbrowser, and swift which is an IRC interface)