Implementig err crate and new actix web
This commit is contained in:
parent
e6780761e9
commit
6c337448f3
17
Cargo.lock
generated
17
Cargo.lock
generated
@ -183,11 +183,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "actix-web-utils"
|
name = "actix-web-utils"
|
||||||
version = "0.2.14"
|
version = "0.2.21"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "git+https://github.com/franklinblanco/actix-web-utils.git#416e44e849a4911fde589424a703236585192365"
|
||||||
checksum = "3ebb116655f5320fb6c805b011884f54980df2e88fce92758bdd5b0579032e15"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-web",
|
"actix-web",
|
||||||
|
"err",
|
||||||
"log",
|
"log",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@ -423,6 +423,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-web-utils",
|
"actix-web-utils",
|
||||||
"dev-dtos",
|
"dev-dtos",
|
||||||
|
"err",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"serde",
|
"serde",
|
||||||
"tokio",
|
"tokio",
|
||||||
@ -431,7 +432,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "dev-dtos"
|
name = "dev-dtos"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://backend:Eo1n1TPsyWV7wwo9uFwgUJGKKheMM6paM2mDkVPA4zqkh5dt6Q6XPkbtojzYQudQsM84vSwKmhHHTPjyn535d6NLBmA3meeGj0Gb8if4sceAwvySdmzedg5mN2P5zzQt@gitea.blancoinfante.com/blancoinfante_backend/dev-dtos-rust.git#80abf74269baf13b9fc1d186516564b0d4521270"
|
source = "git+https://github.com/franklinblanco/user-dtos.git#3b3ffde695753edb4e7ffdf722299b372f2c0bd0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"serde",
|
"serde",
|
||||||
@ -456,6 +457,14 @@ dependencies = [
|
|||||||
"cfg-if",
|
"cfg-if",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "err"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "git+https://github.com/franklinblanco/err.git#42237f4a4be71530933f920f7e5eb6dbf1d0c75e"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fastrand"
|
name = "fastrand"
|
||||||
version = "1.8.0"
|
version = "1.8.0"
|
||||||
|
@ -10,7 +10,8 @@ edition = "2021"
|
|||||||
tokio = { version = "1.20.1", features = ["full"] }
|
tokio = { version = "1.20.1", features = ["full"] }
|
||||||
reqwest = { version = "0.11.11", features = [ "json", "blocking" ]}
|
reqwest = { version = "0.11.11", features = [ "json", "blocking" ]}
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
actix-web-utils = "0.2.5"
|
|
||||||
|
|
||||||
#openssl = { version = "0.10", features = ["vendored"] }
|
#openssl = { version = "0.10", features = ["vendored"] }
|
||||||
dev-dtos = { git = "https://backend:Eo1n1TPsyWV7wwo9uFwgUJGKKheMM6paM2mDkVPA4zqkh5dt6Q6XPkbtojzYQudQsM84vSwKmhHHTPjyn535d6NLBmA3meeGj0Gb8if4sceAwvySdmzedg5mN2P5zzQt@gitea.blancoinfante.com/blancoinfante_backend/dev-dtos-rust.git" }
|
err = { git = "https://github.com/franklinblanco/err.git" }
|
||||||
|
dev-dtos = { git = "https://github.com/franklinblanco/user-dtos.git" }
|
||||||
|
actix-web-utils = { git = "https://github.com/franklinblanco/actix-web-utils.git" }
|
@ -1,4 +1,4 @@
|
|||||||
use actix_web_utils::{enums::error::Error, dtos::message::MessageResource};
|
use err::{Error, MessageResource};
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use serde::{Serialize, de::DeserializeOwned};
|
use serde::{Serialize, de::DeserializeOwned};
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ pub async fn perform_request<B: Serialize, R: DeserializeOwned>(
|
|||||||
true => {
|
true => {
|
||||||
match res.json::<R>().await {
|
match res.json::<R>().await {
|
||||||
Ok(resp_dto) => Ok(resp_dto), // Return correctly deserialized obj
|
Ok(resp_dto) => Ok(resp_dto), // Return correctly deserialized obj
|
||||||
Err(err) => Err(Error::ClientError(MessageResource::new_from_err(err))),
|
Err(err) => Err(Error::Serde(MessageResource::from(err))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
false => {
|
false => {
|
||||||
@ -41,7 +41,7 @@ pub async fn perform_request<B: Serialize, R: DeserializeOwned>(
|
|||||||
res.status().as_u16(),
|
res.status().as_u16(),
|
||||||
match res.json::<Vec<MessageResource>>().await {
|
match res.json::<Vec<MessageResource>>().await {
|
||||||
Ok(messages) => messages,
|
Ok(messages) => messages,
|
||||||
Err(e) => vec![MessageResource::new_from_err(e.to_string())],
|
Err(e) => vec![MessageResource::from(e)],
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ pub async fn perform_request<B: Serialize, R: DeserializeOwned>(
|
|||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
// Request couldn't be sent
|
// Request couldn't be sent
|
||||||
Err(Error::ClientError(MessageResource::new_from_err(e)))
|
Err(Error::Network(MessageResource::from(e)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ pub async fn perform_request_without_client<B: Serialize, R: DeserializeOwned>(
|
|||||||
true => {
|
true => {
|
||||||
match res.json::<R>().await {
|
match res.json::<R>().await {
|
||||||
Ok(resp_dto) => Ok(resp_dto), // Return correctly deserialized obj
|
Ok(resp_dto) => Ok(resp_dto), // Return correctly deserialized obj
|
||||||
Err(err) => Err(Error::ClientError(MessageResource::new_from_err(err))),
|
Err(err) => Err(Error::Serde(MessageResource::from(err))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
false => {
|
false => {
|
||||||
@ -94,7 +94,7 @@ pub async fn perform_request_without_client<B: Serialize, R: DeserializeOwned>(
|
|||||||
res.status().as_u16(),
|
res.status().as_u16(),
|
||||||
match res.json::<Vec<MessageResource>>().await {
|
match res.json::<Vec<MessageResource>>().await {
|
||||||
Ok(messages) => messages,
|
Ok(messages) => messages,
|
||||||
Err(e) => vec![MessageResource::new_from_err(e.to_string())],
|
Err(e) => vec![MessageResource::from(e)],
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@ -102,7 +102,7 @@ pub async fn perform_request_without_client<B: Serialize, R: DeserializeOwned>(
|
|||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
// Request couldn't be sent
|
// Request couldn't be sent
|
||||||
Err(Error::ClientError(MessageResource::new_from_err(e)))
|
Err(Error::Network(MessageResource::from(e)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,7 +136,7 @@ pub fn perform_request_without_client_sync<B: Serialize, R: DeserializeOwned>(
|
|||||||
true => {
|
true => {
|
||||||
match res.json::<R>() {
|
match res.json::<R>() {
|
||||||
Ok(resp_dto) => Ok(resp_dto), // Return correctly deserialized obj
|
Ok(resp_dto) => Ok(resp_dto), // Return correctly deserialized obj
|
||||||
Err(err) => Err(Error::ClientError(MessageResource::new_from_err(err))),
|
Err(err) => Err(Error::Serde(MessageResource::from(err))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
false => {
|
false => {
|
||||||
@ -146,7 +146,7 @@ pub fn perform_request_without_client_sync<B: Serialize, R: DeserializeOwned>(
|
|||||||
res.status().as_u16(),
|
res.status().as_u16(),
|
||||||
match res.json::<Vec<MessageResource>>() {
|
match res.json::<Vec<MessageResource>>() {
|
||||||
Ok(messages) => messages,
|
Ok(messages) => messages,
|
||||||
Err(e) => vec![MessageResource::new_from_err(e.to_string())],
|
Err(e) => vec![MessageResource::from(e)],
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@ -154,7 +154,7 @@ pub fn perform_request_without_client_sync<B: Serialize, R: DeserializeOwned>(
|
|||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
// Request couldn't be sent
|
// Request couldn't be sent
|
||||||
Err(Error::ClientError(MessageResource::new_from_err(e)))
|
Err(Error::Network(MessageResource::from(e)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
use actix_web_utils::enums::error::Error;
|
|
||||||
use dev_dtos::{dtos::user::user_dtos::{UserForCreationDto, UserForLoginDto, UserForAuthenticationDto}, domain::user::{user::User, token::Token}};
|
use dev_dtos::{dtos::user::user_dtos::{UserForCreationDto, UserForLoginDto, UserForAuthenticationDto}, domain::user::{user::User, token::Token}};
|
||||||
|
use err::Error;
|
||||||
use reqwest::{Client, Method};
|
use reqwest::{Client, Method};
|
||||||
|
|
||||||
use crate::middleware::client::perform_request;
|
use crate::middleware::client::perform_request;
|
||||||
|
Loading…
Reference in New Issue
Block a user