Change create channel method to return Channel

Previously returned a Response object.
This commit is contained in:
bitfl0wer 2023-05-23 13:50:39 +02:00
parent 12095132d5
commit 81885cffc0
1 changed files with 14 additions and 3 deletions

View File

@ -137,7 +137,7 @@ impl types::Guild {
schema: schemas::ChannelCreateSchema, schema: schemas::ChannelCreateSchema,
limits_user: &mut Limits, limits_user: &mut Limits,
limits_instance: &mut Limits, limits_instance: &mut Limits,
) -> Result<reqwest::Response, InstanceServerError> { ) -> Result<types::Channel, InstanceServerError> {
types::Channel::create( types::Channel::create(
token, token,
url_api, url_api,
@ -172,13 +172,13 @@ impl types::Channel {
schema: schemas::ChannelCreateSchema, schema: schemas::ChannelCreateSchema,
limits_user: &mut Limits, limits_user: &mut Limits,
limits_instance: &mut Limits, limits_instance: &mut Limits,
) -> Result<reqwest::Response, InstanceServerError> { ) -> Result<types::Channel, InstanceServerError> {
let request = Client::new() let request = Client::new()
.post(format!("{}/guilds/{}/channels/", url_api, guild_id)) .post(format!("{}/guilds/{}/channels/", url_api, guild_id))
.bearer_auth(token) .bearer_auth(token)
.body(to_string(&schema).unwrap()); .body(to_string(&schema).unwrap());
let mut requester = LimitedRequester::new().await; let mut requester = LimitedRequester::new().await;
requester let result = match requester
.send_request( .send_request(
request, request,
crate::api::limits::LimitType::Guild, crate::api::limits::LimitType::Guild,
@ -186,5 +186,16 @@ impl types::Channel {
limits_user, limits_user,
) )
.await .await
{
Ok(result) => result,
Err(e) => return Err(e),
};
match from_str::<types::Channel>(&result.text().await.unwrap()) {
Ok(object) => Ok(object),
Err(e) => Err(InstanceServerError::RequestErrorError {
url: url_api.to_string(),
error: e.to_string(),
}),
}
} }
} }