diff --git a/services/identity/src/client_service.rs b/services/identity/src/client_service.rs --- a/services/identity/src/client_service.rs +++ b/services/identity/src/client_service.rs @@ -4,6 +4,7 @@ use std::str::FromStr; +use crate::error::Error as DBError; use crate::{ client_service::client_proto::{ AddReservedUsernamesRequest, DeleteUserRequest, Empty, @@ -21,7 +22,7 @@ WalletLoginRequest, WalletLoginResponse, }, config::CONFIG, - database::{DatabaseClient, Error as DBError, KeyPayload}, + database::{DatabaseClient, KeyPayload}, id::generate_uuid, nonce::generate_nonce_data, reserved_users::{ diff --git a/services/identity/src/database.rs b/services/identity/src/database.rs --- a/services/identity/src/database.rs +++ b/services/identity/src/database.rs @@ -4,13 +4,13 @@ use std::str::FromStr; use std::sync::Arc; +use crate::error::{DBItemAttributeError, DBItemError, Error}; use aws_config::SdkConfig; use aws_sdk_dynamodb::model::{AttributeValue, PutRequest, WriteRequest}; use aws_sdk_dynamodb::output::{ DeleteItemOutput, GetItemOutput, PutItemOutput, QueryOutput, }; -use aws_sdk_dynamodb::types::Blob; -use aws_sdk_dynamodb::{Client, Error as DynamoDBError}; +use aws_sdk_dynamodb::{types::Blob, Client}; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use tracing::{debug, error, info, warn}; @@ -844,53 +844,6 @@ } } -#[derive( - Debug, derive_more::Display, derive_more::From, derive_more::Error, -)] -pub enum Error { - #[display(...)] - AwsSdk(DynamoDBError), - #[display(...)] - Attribute(DBItemError), -} - -#[derive(Debug, derive_more::Error, derive_more::Constructor)] -pub struct DBItemError { - attribute_name: &'static str, - attribute_value: Option, - attribute_error: DBItemAttributeError, -} - -impl Display for DBItemError { - fn fmt(&self, f: &mut Formatter) -> FmtResult { - match &self.attribute_error { - DBItemAttributeError::Missing => { - write!(f, "Attribute {} is missing", self.attribute_name) - } - DBItemAttributeError::IncorrectType => write!( - f, - "Value for attribute {} has incorrect type: {:?}", - self.attribute_name, self.attribute_value - ), - error => write!( - f, - "Error regarding attribute {} with value {:?}: {}", - self.attribute_name, self.attribute_value, error - ), - } - } -} - -#[derive(Debug, derive_more::Display, derive_more::Error)] -pub enum DBItemAttributeError { - #[display(...)] - Missing, - #[display(...)] - IncorrectType, - #[display(...)] - InvalidTimestamp(chrono::ParseError), -} - type AttributeName = String; fn create_simple_primary_key( diff --git a/services/identity/src/error.rs b/services/identity/src/error.rs new file mode 100644 --- /dev/null +++ b/services/identity/src/error.rs @@ -0,0 +1,51 @@ +use aws_sdk_dynamodb::{model::AttributeValue, Error as DynamoDBError}; +use std::fmt::{Display, Formatter, Result as FmtResult}; + +#[derive( + Debug, derive_more::Display, derive_more::From, derive_more::Error, +)] +pub enum Error { + #[display(...)] + AwsSdk(DynamoDBError), + #[display(...)] + Attribute(DBItemError), + #[display(...)] + MissingItem, +} + +#[derive(Debug, derive_more::Error, derive_more::Constructor)] +pub struct DBItemError { + pub attribute_name: &'static str, + pub attribute_value: Option, + pub attribute_error: DBItemAttributeError, +} + +impl Display for DBItemError { + fn fmt(&self, f: &mut Formatter) -> FmtResult { + match &self.attribute_error { + DBItemAttributeError::Missing => { + write!(f, "Attribute {} is missing", self.attribute_name) + } + DBItemAttributeError::IncorrectType => write!( + f, + "Value for attribute {} has incorrect type: {:?}", + self.attribute_name, self.attribute_value + ), + error => write!( + f, + "Error regarding attribute {} with value {:?}: {}", + self.attribute_name, self.attribute_value, error + ), + } + } +} + +#[derive(Debug, derive_more::Display, derive_more::Error)] +pub enum DBItemAttributeError { + #[display(...)] + Missing, + #[display(...)] + IncorrectType, + #[display(...)] + InvalidTimestamp(chrono::ParseError), +} diff --git a/services/identity/src/main.rs b/services/identity/src/main.rs --- a/services/identity/src/main.rs +++ b/services/identity/src/main.rs @@ -9,6 +9,7 @@ mod config; pub mod constants; mod database; +pub mod error; mod grpc_services; mod id; mod keygen;