neon_arch commited on
Commit
019b332
1 Parent(s): 318be6e

chore: add enum to handle different reqwest errors & add timeout to requests

Browse files
src/engines/duckduckgo.rs CHANGED
@@ -2,7 +2,7 @@
2
  //! by querying the upstream duckduckgo search engine with user provided query and with a page
3
  //! number if provided.
4
 
5
- use std::collections::HashMap;
6
 
7
  use reqwest::header::{HeaderMap, CONTENT_TYPE, COOKIE, REFERER, USER_AGENT};
8
  use scraper::{Html, Selector};
@@ -57,6 +57,7 @@ pub async fn results(
57
  // TODO: Write better error handling code to handle no results case.
58
  let results: String = reqwest::Client::new()
59
  .get(url)
 
60
  .headers(header_map) // add spoofed headers to emulate human behaviour
61
  .send()
62
  .await?
 
2
  //! by querying the upstream duckduckgo search engine with user provided query and with a page
3
  //! number if provided.
4
 
5
+ use std::{collections::HashMap, time::Duration};
6
 
7
  use reqwest::header::{HeaderMap, CONTENT_TYPE, COOKIE, REFERER, USER_AGENT};
8
  use scraper::{Html, Selector};
 
57
  // TODO: Write better error handling code to handle no results case.
58
  let results: String = reqwest::Client::new()
59
  .get(url)
60
+ .timeout(Duration::from_secs(30))
61
  .headers(header_map) // add spoofed headers to emulate human behaviour
62
  .send()
63
  .await?
src/engines/engine_models.rs ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ #[derive(Debug)]
2
+ pub enum ReqwestError{
3
+ NotFound,
4
+ Timeout,
5
+ Forbidden,
6
+ AccessDenied,
7
+ TooManyRequests
8
+ }
src/engines/mod.rs CHANGED
@@ -1,2 +1,3 @@
1
  pub mod duckduckgo;
 
2
  pub mod searx;
 
1
  pub mod duckduckgo;
2
+ pub mod engine_models;
3
  pub mod searx;