shuppet / raku-api-discord

Raku module for interacting with the Discord API.
https://shuppet.com
BSD 3-Clause "New" or "Revised" License
30 stars 3 forks source link

Channel.trigger-typing crashes with "411 Length required" #17

Closed throwaway-30964 closed 5 years ago

throwaway-30964 commented 5 years ago
  whenever $discord.events -> $event {
    if $event<t> eq 'TYPING_START' {
      my $channel = await $discord.get-channel($event<d><channel_id>);
      await $channel.trigger-typing;
    }
  }

Crashes with:

Died because of the exception:
    An operation first awaited:
      [...]                                                                     

    Died with the exception:
        Server responded with 411 Length Required
          in block  at [...]/BD9BD084131C6E7D2BF4FE09570E5EBE604DB8FA (Cro::HTTP::Client) line 410    

The problem seems to be that the request doesn't contain a Content-Length header:

The HyperText Transfer Protocol (HTTP) 411 Length Required client error response code indicates that the server refuses to accept the request without a defined Content-Length header.

throwaway-30964 commented 5 years ago

The fix is trivial, just add an empty body here https://github.com/shuppet/p6-api-discord/blob/master/lib/API/Discord/Channel.pm6#L135

$.api.rest.post(endpoint-for(self, 'trigger-typing'), :body(''));
kawaii commented 5 years ago

Thanks for the report and provided patch!