Skip to content

Commit

Permalink
Fix guild leaving result
Browse files Browse the repository at this point in the history
When leaving a guild, `rest::leave_guild` would attempt to deserialize a
JSON body containing a partial amount of guild info, resulting in an
error:

```
Could not leave guild: Json(ErrorImpl { code: EofWhileParsingValue, line: 1, column: 0 })
```

Although the bot would still actually leave the guild, it would always
return this error.

To fix this, don't try to deserialize anything and only check for a 204
instead.
  • Loading branch information
Zeyla Hellyer committed May 6, 2017
1 parent 970d726 commit ae352ea
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 10 deletions.
9 changes: 2 additions & 7 deletions src/client/rest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1341,13 +1341,8 @@ pub fn leave_group(guild_id: u64) -> Result<Group> {
}

/// Leaves a guild.
pub fn leave_guild(guild_id: u64) -> Result<PartialGuild> {
let response = request!(Route::UsersMeGuildsId,
delete,
"/users/@me/guilds/{}",
guild_id);

serde_json::from_reader::<HyperResponse, PartialGuild>(response).map_err(From::from)
pub fn leave_guild(guild_id: u64) -> Result<()> {
verify(204, request!(Route::UsersMeGuildsId, delete, "/users/@me/guilds/{}", guild_id))
}

/// Deletes a user from group DM.
Expand Down
2 changes: 1 addition & 1 deletion src/model/guild/guild_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ impl GuildId {

/// Leaves the guild.
#[inline]
pub fn leave(&self) -> Result<PartialGuild> {
pub fn leave(&self) -> Result<()> {
rest::leave_guild(self.0)
}

Expand Down
2 changes: 1 addition & 1 deletion src/model/guild/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ impl Guild {

/// Leaves the guild.
#[inline]
pub fn leave(&self) -> Result<PartialGuild> {
pub fn leave(&self) -> Result<()> {
self.id.leave()
}

Expand Down
2 changes: 1 addition & 1 deletion src/model/guild/partial_guild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ impl PartialGuild {

/// Leaves the guild.
#[inline]
pub fn leave(&self) -> Result<PartialGuild> {
pub fn leave(&self) -> Result<()> {
self.id.leave()
}

Expand Down

0 comments on commit ae352ea

Please sign in to comment.