-
-
Notifications
You must be signed in to change notification settings - Fork 363
/
errors.rs
64 lines (61 loc) · 2.79 KB
/
errors.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use crate::{args, get_vars};
pub use failure::{Error, ResultExt};
use std::error::Error as stdError;
pub type Result<T> = ::std::result::Result<T, Error>;
pub fn check_request_errors(error: reqwest::Error, api: &str, quiet_flag: bool) {
if !quiet_flag {
if error.is_timeout() {
eprintln!(
"⏳ A timeout error has occurred while processing the request in the {} API. Error description: {}",
&api, &error.description())
} else if error.is_redirect() {
eprintln!(
"❌ A redirect was found while processing the {} API. Error description: {}",
&api,
&error.description()
)
} else if error.is_client_error() {
eprintln!(
"❌ A client error has occurred sending the request to the {} API. Error description: {}",
&api,
&error.description()
)
} else if error.is_server_error() {
eprintln!(
"❌ A server error has occurred sending the request to the {} API. Error description: {}",
&api,
&error.description()
)
} else {
eprintln!(
"❌ An error has occurred while procesing the request in the {} API. Error description: {}",
&api,
&error.description()
)
}
}
}
pub fn check_json_errors(error: reqwest::Error, api: &str, quiet_flag: bool) {
if !quiet_flag {
eprintln!("❌ An error occurred while parsing the JSON obtained from the {} API. Error description: {}.", &api, error.description())
}
}
pub fn check_monitoring_parameters(args: &mut args::Args) -> Result<()> {
if args.monitoring_flag
&& args.discord_webhook.is_empty()
&& args.slack_webhook.is_empty()
&& args.telegram_bot_token.is_empty()
{
eprintln!("You need to configure at least one webhook variable in your system. For Discord set the findomain_discord_webhook system variable, for Slack set the findomain_slack_webhook variable, for Telegram set the findomain_telegrambot_token and findomain_telegrambot_chat_id valriables. See https://git.io/JeZQW for more information, exiting.");
std::process::exit(1)
} else if !args.telegram_bot_token.is_empty() && args.telegram_chat_id.is_empty() {
eprintln!("You have configured the findomain_telegrambot_token variable but not the findomain_telegrambot_chat_id variable, it's required. See https://git.io/JeZQW for more information, exiting.");
std::process::exit(1)
} else if !args.telegram_bot_token.is_empty() && !args.telegram_chat_id.is_empty() {
args.telegram_webhook = format!(
"https://api.telegram.org/bot{}/sendMessage",
get_vars::get_auth_token("telegram")
)
}
Ok(())
}