Skip to content

Commit

Permalink
feat: add more errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomio committed Jun 18, 2022
1 parent 308332e commit bcb7e12
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/error.rs
Expand Up @@ -26,6 +26,8 @@ pub enum Error {
FailedToConnect,
#[display(fmt = "An error occured when accessing the website.")]
WebsiteError,
#[display(fmt = "You provided an invalid window size.")]
InvalidWindowSize,
}

impl ResponseError for Error {
Expand All @@ -40,7 +42,8 @@ impl ResponseError for Error {
Error::InvalidUrl
| Error::MissingAuthToken
| Error::FailedToConnect
| Error::WebsiteError => StatusCode::BAD_REQUEST,
| Error::WebsiteError
| Error::InvalidWindowSize => StatusCode::BAD_REQUEST,
Error::Unauthorized => StatusCode::UNAUTHORIZED,
Error::ScreenshotNotFound => StatusCode::NOT_FOUND,
Error::UrlNotSafeForWork => StatusCode::FORBIDDEN,
Expand Down
4 changes: 2 additions & 2 deletions src/routes/screenshot.rs
Expand Up @@ -65,8 +65,8 @@ pub async fn screenshot(

let client = &data.browser;

client.goto(url.as_str()).await.expect("Failed navigating to site");
client.set_window_size(1980, 1080).await.expect("Failed setting window size");
client.goto(url.as_str()).await.map_err(|_| Error::WebsiteError)?;
client.set_window_size(1980, 1080).await.map_err(|_| Error::InvalidWindowSize)?;
client
.execute(
"\
Expand Down

0 comments on commit bcb7e12

Please sign in to comment.