Skip to content

Commit

Permalink
(Fix) Added error handling to client (reqwest) building
Browse files Browse the repository at this point in the history
  • Loading branch information
xairaven committed Jan 15, 2025
1 parent 97cec8c commit d0b1c44
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"Start": "<b>Welcome to the Media Downloader Bot!</b>\n\n<b>Commands:</b>\n- /help: Display this help message.\n\n<b>How to use:</b>\nTo download media from TikTok or Instagram, simply send a link directly to the bot.\nThe bot will process the link and send the media file back to you.\n\n<b>Additional Notes:</b>\nEnsure that content is directly accessible (not private or restricted).\n\n<b>Supported formats:</b>\n- TikTok Videos;\n- TikTok Photo Slides;\n- Instagram Reels;\n- Instagram Stories;\n- Instagram Photos;\n- Instagram Slides.",
"Help": "<b>Commands:</b>\n- /help: Display this help message.\n\n<b>How to use:</b>\nTo download media from TikTok or Instagram, simply send a link directly to the bot.\nThe bot will process the link and send the media file back to you.\n\n<b>Additional Notes:</b>\nEnsure that content is directly accessible (not private or restricted).\n\n<b>Supported formats:</b>\n- TikTok Videos;\n- TikTok Photo Slides;\n- Instagram Reels;\n- Instagram Stories;\n- Instagram Photos;\n- Instagram Slides.",

"ClientBuildingFailed": "Failed to build Client (reqwest).",
"FailedGetResponse": "Failed to get a response from API.",
"FailedParseResponse": "Failed to parse response.",
"FailedParseUrl": "Failed to parse final url.",
Expand Down
3 changes: 3 additions & 0 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ impl Response {

#[derive(Debug, Error)]
pub enum ApiError {
#[error("ClientBuildingFailed")]
ClientBuildingFailed,

#[error("FailedGetResponse")]
FailedGetResponse,

Expand Down
2 changes: 1 addition & 1 deletion src/api/instagram/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async fn request(
let client = reqwest::Client::builder()
.redirect(reqwest::redirect::Policy::none())
.build()
.unwrap();
.map_err(|_| ApiError::ClientBuildingFailed)?;

let request_body = match content_type {
ContentType::Photos | ContentType::Reels => format!(
Expand Down
2 changes: 1 addition & 1 deletion src/api/tiktok/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async fn request(api_key: &str, link: &str) -> Result<String, ApiError> {
let client = reqwest::Client::builder()
.redirect(reqwest::redirect::Policy::none())
.build()
.unwrap();
.map_err(|_| ApiError::ClientBuildingFailed)?;

let request_body = format!(
"https://tiktok-download-without-watermark.p.rapidapi.com/analysis?url={}&hd=0",
Expand Down

0 comments on commit d0b1c44

Please sign in to comment.