use reqwest::header::{CONTENT_TYPE, HeaderValue};
use thiserror::Error;
use crate::message::Message;
#[derive(Debug, Error)]
pub enum DiscordError {
#[error("Discord.JSON - {0}")]
Json(#[from] serde_json::Error),
#[error("Discord.Reqwest - {0}")]
Reqwest(#[from] reqwest::Error),
}
const APPLICATION_JSON: HeaderValue = HeaderValue::from_static("application/json");
impl<'a> Message<'a> {
pub async fn send(mut self) -> Result<(), DiscordError> {
self.truncate();
let body = serde_json::to_string(&self.json)?;
self.client
.post(self.url)
.header(CONTENT_TYPE, APPLICATION_JSON)
.body(body)
.send()
.await?
.error_for_status()?;
Ok(())
}
}