diff --git a/src/db_operations/transactions/error.rs b/src/db_operations/transactions/error.rs index 8462669..2537e75 100644 --- a/src/db_operations/transactions/error.rs +++ b/src/db_operations/transactions/error.rs @@ -1,4 +1,6 @@ -use my_no_sql_sdk::core::db_json_entity::DbEntityParseFail; +use my_no_sql_sdk::core::{ + db_json_entity::DbEntityParseFail, my_json::json_reader::JsonParseError, +}; use crate::db_operations::DbOperationError; @@ -8,6 +10,13 @@ pub enum TransactionOperationError { DbEntityParseFail(DbEntityParseFail), DbOperationError(DbOperationError), SerdeJsonError(serde_json::Error), + JsonParseError(JsonParseError), +} + +impl From for TransactionOperationError { + fn from(src: JsonParseError) -> Self { + Self::JsonParseError(src) + } } impl From for TransactionOperationError { diff --git a/src/db_transactions/json_parser/parser.rs b/src/db_transactions/json_parser/parser.rs index e4d9b06..81220b8 100644 --- a/src/db_transactions/json_parser/parser.rs +++ b/src/db_transactions/json_parser/parser.rs @@ -20,7 +20,7 @@ const JSON_TRANSACTION_INSERT_OR_UPDATE: &str = "InsertOrUpdate"; pub fn parse_transactions( payload: &[u8], ) -> Result, TransactionOperationError> { - let mut json_array_iterator: JsonArrayIterator = payload.into(); + let mut json_array_iterator: JsonArrayIterator = payload.try_into()?; let mut result = Vec::new(); diff --git a/src/http/mappers/transaction_operation_error.rs b/src/http/mappers/transaction_operation_error.rs index 679396e..7aa788d 100644 --- a/src/http/mappers/transaction_operation_error.rs +++ b/src/http/mappers/transaction_operation_error.rs @@ -23,6 +23,14 @@ impl From for HttpFailResult { write_telemetry: true, write_to_log: true, }, + + TransactionOperationError::JsonParseError(err) => HttpFailResult { + content: format!("{:?}", err).into_bytes(), + content_type: WebContentType::Text, + status_code: 500, + write_telemetry: true, + write_to_log: true, + }, } } } diff --git a/src/persist_operations/serializers/db_partition.rs b/src/persist_operations/serializers/db_partition.rs index 1c90d92..2420353 100644 --- a/src/persist_operations/serializers/db_partition.rs +++ b/src/persist_operations/serializers/db_partition.rs @@ -7,7 +7,16 @@ use my_no_sql_server_core::rust_extensions::array_of_bytes_iterator::SliceIterat pub fn deserialize(partition_key: &str, raw: &[u8]) -> Result { let mut db_partition = DbPartition::new(partition_key.to_string()); - let mut json_array_iterator: JsonArrayIterator = raw.into(); + let json_array_iterator: Result, _> = raw.try_into(); + + if let Err(err) = json_array_iterator { + return Err(format!( + "Can not split to array of json objects for partition key: {}. Err: {:?}", + partition_key, err + )); + } + + let mut json_array_iterator = json_array_iterator.unwrap(); while let Some(db_entity_json_result) = json_array_iterator.get_next() { if let Err(err) = db_entity_json_result {