twitchdev / issues

Issue tracker for third party developers.
Apache License 2.0
73 stars 6 forks source link

Delete Chat Messages API returns 500 on invalid broadcaster_id #937

Closed Xemdo closed 4 months ago

Xemdo commented 5 months ago

When running Delete Chat Messages, if you put in a broadcaster_id that does not exist it returns 500:

Not working (message_id as broadcaster_id):

$ twitch api delete moderation/chat -q broadcaster_id="0b9a0b82-83ce-4fd4-8dc7-3c792898501b" -q moderator_id=57047445 -q message_id="0b9a0b82-83ce-4fd4-8dc7-3c792898501b"
{
  "data": [],
  "error": "Internal Server Error",
  "status": 500
}

Not working (standard user id, doesn't exist):

$ twitch api delete moderation/chat -q broadcaster_id="23749723947329839" -q moderator_id=57047445 -q message_id="0b9a0b82-83ce-4fd4-8dc7-3c792898501b"
{
  "data": [],
  "error": "Internal Server Error",
  "status": 500
}

Working:

$ twitch api delete moderation/chat -q broadcaster_id=57047445 -q moderator_id=57047445 -q message_id="0b9a0b82-83ce-4fd4-8dc7-3c792898501b"
Endpoint responded with status 204
Xemdo commented 5 months ago

Ticketed internally as APIPLAT-4685

thedist commented 5 months ago

This may be related to the similar inconsistency with handling certain user id's in other endpoints (for example, any user id that is numerically >= 2^31). So for example Get Users will return an empty data array for 2147483647, but 2147483648 or higher returns a 400 error with the message Invalid username(s), email(s), or ID(s). Bad Identifiers..

Other endpoints handle such user id's differently, for example Get Streams just returns an empty data array as if the users stream isn't live, even if the user_id is malformed. In this case of Delete Chat Message it returns a 500, which IIRC some other endpoints also do but I'd have to test.

So how bad user id's are handled differ depending on which endpoint is used.

Xemdo commented 5 months ago

In this case it doesn't appear to fail due to failure to parse as a 32-bit integer, as changing it to a User ID that doesn't exist below 2147483648 still returns 500:

twitch api delete moderation/chat -q broadcaster_id="2000000000" -q moderator_id=57047445 -q message_id="0b9a0b82-83ce-4fd4-8dc7-3c792898501b"
{
  "data": [],
  "error": "Internal Server Error",
  "status": 500
}

Returning 400 on other endpoints due to that reason is interesting, though, and definitely needs some investigation for future-proofing.

Xemdo commented 4 months ago

Fixed.