unite PageErrors

This commit is contained in:
Quaternions 2024-10-01 11:30:37 -07:00
parent ac674778f6
commit 94792ebf02

View File

@ -103,16 +103,16 @@ pub struct AssetVersionsPageResponse{
pub data:Vec<AssetVersion>,
}
#[derive(Debug)]
pub enum AssetVersionsPageError{
pub enum PageError{
ParseError(url::ParseError),
Reqwest(reqwest::Error),
}
impl std::fmt::Display for AssetVersionsPageError{
impl std::fmt::Display for PageError{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f,"{self:?}")
}
}
impl std::error::Error for AssetVersionsPageError{}
impl std::error::Error for PageError{}
pub enum Owner{
User(u64),
@ -149,17 +149,6 @@ pub struct CreationsPageResponse{
pub nextPageCursor:Option<String>,
pub data:Vec<CreationsItem>,
}
#[derive(Debug)]
pub enum CreationsPageError{
ParseError(url::ParseError),
Reqwest(reqwest::Error),
}
impl std::fmt::Display for CreationsPageError{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f,"{self:?}")
}
}
impl std::error::Error for CreationsPageError{}
//idk how to do this better
enum ReaderType<R:std::io::Read>{
@ -300,8 +289,8 @@ impl CookieContext{
Err(e)=>Err(e),
}.map_err(GetError::IO)
}
pub async fn get_asset_versions_page(&self,config:AssetVersionsPageRequest)->Result<AssetVersionsPageResponse,AssetVersionsPageError>{
let mut url=reqwest::Url::parse(format!("https://develop.roblox.com/v1/assets/{}/saved-versions",config.asset_id).as_str()).map_err(AssetVersionsPageError::ParseError)?;
pub async fn get_asset_versions_page(&self,config:AssetVersionsPageRequest)->Result<AssetVersionsPageResponse,PageError>{
let mut url=reqwest::Url::parse(format!("https://develop.roblox.com/v1/assets/{}/saved-versions",config.asset_id).as_str()).map_err(PageError::ParseError)?;
//url borrow scope
{
let mut query=url.query_pairs_mut();//borrow here
@ -313,13 +302,13 @@ impl CookieContext{
}
}
self.get(url).await.map_err(AssetVersionsPageError::Reqwest)?
.error_for_status().map_err(AssetVersionsPageError::Reqwest)?
.json::<AssetVersionsPageResponse>().await.map_err(AssetVersionsPageError::Reqwest)
self.get(url).await.map_err(PageError::Reqwest)?
.error_for_status().map_err(PageError::Reqwest)?
.json::<AssetVersionsPageResponse>().await.map_err(PageError::Reqwest)
}
pub async fn get_creations_page(&self,config:&CreationsPageRequest)->Result<CreationsPageResponse,CreationsPageError>{
pub async fn get_creations_page(&self,config:&CreationsPageRequest)->Result<CreationsPageResponse,PageError>{
let (owner,id)=config.owner.get_url_info();
let mut url=reqwest::Url::parse(format!("https://apis.roblox.com/toolbox-service/v1/creations/{}/{}/10?limit=50",owner,id).as_str()).map_err(CreationsPageError::ParseError)?;
let mut url=reqwest::Url::parse(format!("https://apis.roblox.com/toolbox-service/v1/creations/{}/{}/10?limit=50",owner,id).as_str()).map_err(PageError::ParseError)?;
//url borrow scope
{
let mut query=url.query_pairs_mut();//borrow here
@ -328,8 +317,8 @@ impl CookieContext{
}
}
self.get(url).await.map_err(CreationsPageError::Reqwest)?
.error_for_status().map_err(CreationsPageError::Reqwest)?
.json::<CreationsPageResponse>().await.map_err(CreationsPageError::Reqwest)
self.get(url).await.map_err(PageError::Reqwest)?
.error_for_status().map_err(PageError::Reqwest)?
.json::<CreationsPageResponse>().await.map_err(PageError::Reqwest)
}
}