-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(web-scraping): surface web page content tracker errors in the API…
… responses
- Loading branch information
Showing
6 changed files
with
169 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
mod web_page_content_tracker_tag; | ||
mod web_scraper_content_error; | ||
mod web_scraper_content_request; | ||
mod web_scraper_content_response; | ||
|
||
pub use self::{ | ||
web_page_content_tracker_tag::WebPageContentTrackerTag, | ||
web_scraper_content_error::WebScraperContentError, | ||
web_scraper_content_request::{WebScraperContentRequest, WebScraperContentRequestScripts}, | ||
web_scraper_content_response::WebScraperContentResponse, | ||
}; |
46 changes: 46 additions & 0 deletions
46
src/utils/web_scraping/web_page_trackers/web_page_content/web_scraper_content_error.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// Represents error response if scraper couldn't extract content. | ||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct WebScraperContentError { | ||
/// Error message. | ||
pub message: String, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::WebScraperContentError; | ||
use insta::assert_json_snapshot; | ||
|
||
#[test] | ||
fn deserialization() -> anyhow::Result<()> { | ||
assert_eq!( | ||
serde_json::from_str::<WebScraperContentError>( | ||
r#" | ||
{ | ||
"message": "some-error" | ||
} | ||
"# | ||
)?, | ||
WebScraperContentError { | ||
message: "some-error".to_string(), | ||
} | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn serialization() -> anyhow::Result<()> { | ||
assert_json_snapshot!(WebScraperContentError { | ||
message: "some-error".to_string(), | ||
}, @r###" | ||
{ | ||
"message": "some-error" | ||
} | ||
"###); | ||
|
||
Ok(()) | ||
} | ||
} |