Skip to content

Commit

Permalink
fix: handle error cases when adding invalid ocafile
Browse files Browse the repository at this point in the history
  • Loading branch information
olichwiruk committed Oct 26, 2023
1 parent d664b27 commit 7861044
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
34 changes: 19 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dyn-clonable = "0.9.0"
indexmap = { version = "1.9.3", features = ["serde"] }
isolang = "2.3.0"
oca-parser-xls = { version = "2.0.0-rc.2", optional = true }
oca-rs = "0.3.0-rc.19"
oca-rs = "0.3.3"
rusqlite = "0.29.0"
serde = { version = "1.0", features = ["derive"] }
serde-value = "0.7.0"
Expand Down
16 changes: 15 additions & 1 deletion src/routes/oca_bundles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,21 @@ pub async fn add_oca_file(
item: web::Bytes,
_req: HttpRequest,
) -> HttpResponse {
let ocafile = String::from_utf8(item.to_vec()).unwrap();
let ocafile = match String::from_utf8(item.to_vec()) {
Ok(parsed) => parsed,
Err(e) => {
return HttpResponse::UnprocessableEntity()
.content_type(ContentType::json())
.body(serde_json::to_string(&vec![e.to_string()]).unwrap())
}
};

if ocafile.is_empty() {
let error = "OCA File can't be empty";
return HttpResponse::UnprocessableEntity()
.content_type(ContentType::json())
.body(serde_json::to_string(&vec![error]).unwrap())
}

let result = match oca_facade.lock().unwrap().build_from_ocafile(ocafile) {
Ok(oca_bundle) => {
Expand Down

0 comments on commit 7861044

Please sign in to comment.