mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
Make the 'core.network' module private
This commit is contained in:
parent
0a6dc12f92
commit
e9ebd62993
5 changed files with 33 additions and 32 deletions
|
@ -1,3 +1,3 @@
|
|||
pub mod network;
|
||||
mod network;
|
||||
pub mod requests;
|
||||
pub mod types;
|
||||
|
|
|
@ -3,9 +3,9 @@ use serde::de::DeserializeOwned;
|
|||
use serde_json::Value;
|
||||
use reqwest::{
|
||||
r#async::{Client, multipart::Form},
|
||||
StatusCode,
|
||||
};
|
||||
use apply::Apply;
|
||||
use crate::core::requests::{RequestError, ResponseResult};
|
||||
|
||||
|
||||
const TELEGRAM_API_URL: &str = "https://api.telegram.org";
|
||||
|
@ -31,32 +31,6 @@ fn file_url(base: &str, token: &str, file_path: &str) -> String {
|
|||
)
|
||||
}
|
||||
|
||||
#[derive(Debug, Display)]
|
||||
pub enum RequestError {
|
||||
#[display(fmt = "Telegram error #{}: {}", status_code, description)]
|
||||
ApiError {
|
||||
status_code: StatusCode,
|
||||
description: String,
|
||||
},
|
||||
|
||||
#[display(fmt = "Network error: {err}", err = _0)]
|
||||
NetworkError(reqwest::Error),
|
||||
|
||||
#[display(fmt = "InvalidJson error caused by: {err}", err = _0)]
|
||||
InvalidJson(serde_json::Error),
|
||||
}
|
||||
|
||||
impl std::error::Error for RequestError {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
match self {
|
||||
RequestError::ApiError { .. } => None,
|
||||
RequestError::NetworkError(err) => Some(err),
|
||||
RequestError::InvalidJson(err) => Some(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type ResponseResult<T> = Result<T, RequestError>;
|
||||
|
||||
pub async fn request<T: DeserializeOwned>(
|
||||
client: &Client,
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
use crate::core::{
|
||||
types::User,
|
||||
network::{
|
||||
request, ResponseResult,
|
||||
request,
|
||||
},
|
||||
requests::{
|
||||
Request, RequestInfo, RequestFuture,
|
||||
}
|
||||
};
|
||||
use crate::core::requests::ResponseResult;
|
||||
|
||||
|
||||
#[derive(Debug, Constructor)]
|
||||
|
|
|
@ -1,13 +1,38 @@
|
|||
use std::future::Future;
|
||||
|
||||
use crate::core::network::ResponseResult;
|
||||
|
||||
use serde::de::DeserializeOwned;
|
||||
use reqwest::r#async::Client;
|
||||
use reqwest::StatusCode;
|
||||
|
||||
|
||||
mod form_builder;
|
||||
|
||||
#[derive(Debug, Display)]
|
||||
pub enum RequestError {
|
||||
#[display(fmt = "Telegram error #{}: {}", status_code, description)]
|
||||
ApiError {
|
||||
status_code: StatusCode,
|
||||
description: String,
|
||||
},
|
||||
|
||||
#[display(fmt = "Network error: {err}", err = _0)]
|
||||
NetworkError(reqwest::Error),
|
||||
|
||||
#[display(fmt = "InvalidJson error caused by: {err}", err = _0)]
|
||||
InvalidJson(serde_json::Error),
|
||||
}
|
||||
|
||||
impl std::error::Error for RequestError {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
match self {
|
||||
RequestError::ApiError { .. } => None,
|
||||
RequestError::NetworkError(err) => Some(err),
|
||||
RequestError::InvalidJson(err) => Some(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type ResponseResult<T> = Result<T, RequestError>;
|
||||
|
||||
/// Request that can be sent to telegram.
|
||||
/// `ReturnValue` - a type that will be returned from Telegram.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::core::{
|
||||
types::Message,
|
||||
network::{
|
||||
request, ResponseResult,
|
||||
request,
|
||||
},
|
||||
requests::{
|
||||
form_builder::FormBuilder,
|
||||
|
@ -11,6 +11,7 @@ use crate::core::{
|
|||
RequestFuture,
|
||||
}
|
||||
};
|
||||
use crate::core::requests::ResponseResult;
|
||||
|
||||
|
||||
#[derive(Debug, TypedBuilder)]
|
||||
|
|
Loading…
Reference in a new issue