mirror of
https://github.com/chatmail/core.git
synced 2026-04-18 22:16:30 +03:00
21 lines
490 B
Rust
21 lines
490 B
Rust
use crate::context::Context;
|
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
pub enum Error {
|
|
#[error("URL request error")]
|
|
GetError(surf::Error),
|
|
}
|
|
|
|
pub async fn read_url(context: &Context, url: &str) -> Result<String, Error> {
|
|
info!(context, "Requesting URL {}", url);
|
|
|
|
match surf::get(url).recv_string().await {
|
|
Ok(res) => Ok(res),
|
|
Err(err) => {
|
|
info!(context, "Can\'t read URL {}: {}", url, err);
|
|
|
|
Err(Error::GetError(err))
|
|
}
|
|
}
|
|
}
|