Skip to content

Commit

Permalink
Made way understandable errorrs
Browse files Browse the repository at this point in the history
  • Loading branch information
amigin committed Oct 21, 2024
1 parent 44673b6 commit 826fcc7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/db_operations/transactions/error.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -8,6 +10,13 @@ pub enum TransactionOperationError {
DbEntityParseFail(DbEntityParseFail),
DbOperationError(DbOperationError),
SerdeJsonError(serde_json::Error),
JsonParseError(JsonParseError),
}

impl From<JsonParseError> for TransactionOperationError {
fn from(src: JsonParseError) -> Self {
Self::JsonParseError(src)
}
}

impl From<DbEntityParseFail> for TransactionOperationError {
Expand Down
2 changes: 1 addition & 1 deletion src/db_transactions/json_parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const JSON_TRANSACTION_INSERT_OR_UPDATE: &str = "InsertOrUpdate";
pub fn parse_transactions(
payload: &[u8],
) -> Result<Vec<TransactionalOperationStep>, TransactionOperationError> {
let mut json_array_iterator: JsonArrayIterator<SliceIterator> = payload.into();
let mut json_array_iterator: JsonArrayIterator<SliceIterator> = payload.try_into()?;

let mut result = Vec::new();

Expand Down
8 changes: 8 additions & 0 deletions src/http/mappers/transaction_operation_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ impl From<TransactionOperationError> 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,
},
}
}
}
11 changes: 10 additions & 1 deletion src/persist_operations/serializers/db_partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DbPartition, String> {
let mut db_partition = DbPartition::new(partition_key.to_string());

let mut json_array_iterator: JsonArrayIterator<SliceIterator> = raw.into();
let json_array_iterator: Result<JsonArrayIterator<SliceIterator>, _> = 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 {
Expand Down

0 comments on commit 826fcc7

Please sign in to comment.