Implementig err crate and new actix web

This commit is contained in:
Franklin 2022-09-25 13:20:14 -04:00
parent e6780761e9
commit 6c337448f3
4 changed files with 27 additions and 17 deletions

17
Cargo.lock generated
View File

@ -183,11 +183,11 @@ dependencies = [
[[package]]
name = "actix-web-utils"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ebb116655f5320fb6c805b011884f54980df2e88fce92758bdd5b0579032e15"
version = "0.2.21"
source = "git+https://github.com/franklinblanco/actix-web-utils.git#416e44e849a4911fde589424a703236585192365"
dependencies = [
"actix-web",
"err",
"log",
"serde",
"serde_json",
@ -423,6 +423,7 @@ version = "0.1.0"
dependencies = [
"actix-web-utils",
"dev-dtos",
"err",
"reqwest",
"serde",
"tokio",
@ -431,7 +432,7 @@ dependencies = [
[[package]]
name = "dev-dtos"
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 = [
"chrono",
"serde",
@ -456,6 +457,14 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "err"
version = "0.1.1"
source = "git+https://github.com/franklinblanco/err.git#42237f4a4be71530933f920f7e5eb6dbf1d0c75e"
dependencies = [
"serde",
]
[[package]]
name = "fastrand"
version = "1.8.0"

View File

@ -10,7 +10,8 @@ edition = "2021"
tokio = { version = "1.20.1", features = ["full"] }
reqwest = { version = "0.11.11", features = [ "json", "blocking" ]}
serde = { version = "1.0", features = ["derive"] }
actix-web-utils = "0.2.5"
#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" }

View File

@ -1,4 +1,4 @@
use actix_web_utils::{enums::error::Error, dtos::message::MessageResource};
use err::{Error, MessageResource};
use reqwest::Client;
use serde::{Serialize, de::DeserializeOwned};
@ -31,7 +31,7 @@ pub async fn perform_request<B: Serialize, R: DeserializeOwned>(
true => {
match res.json::<R>().await {
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 => {
@ -41,7 +41,7 @@ pub async fn perform_request<B: Serialize, R: DeserializeOwned>(
res.status().as_u16(),
match res.json::<Vec<MessageResource>>().await {
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) => {
// 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 => {
match res.json::<R>().await {
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 => {
@ -94,7 +94,7 @@ pub async fn perform_request_without_client<B: Serialize, R: DeserializeOwned>(
res.status().as_u16(),
match res.json::<Vec<MessageResource>>().await {
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) => {
// 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 => {
match res.json::<R>() {
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 => {
@ -146,7 +146,7 @@ pub fn perform_request_without_client_sync<B: Serialize, R: DeserializeOwned>(
res.status().as_u16(),
match res.json::<Vec<MessageResource>>() {
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) => {
// Request couldn't be sent
Err(Error::ClientError(MessageResource::new_from_err(e)))
Err(Error::Network(MessageResource::from(e)))
}
}
}

View File

@ -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 err::Error;
use reqwest::{Client, Method};
use crate::middleware::client::perform_request;