-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FIL-461] Get rid of the matches #247
base: main
Are you sure you want to change the base?
Conversation
match LDNApplication::load_from_db(id, owner, repo).await { | ||
Ok(app_file) => match serde_json::to_string_pretty(&app_file) { | ||
Ok(response) => HttpResponse::Ok().body(response), | ||
Err(_) => { | ||
Ok(app_file) => { | ||
if let Ok(response) = serde_json::to_string_pretty(&app_file) { | ||
HttpResponse::Ok().body(response) | ||
} else { | ||
HttpResponse::InternalServerError().body("Failed to serialize success message") | ||
} | ||
}, | ||
} | ||
Err(e) => HttpResponse::BadRequest().body(e.to_string()), | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to refactor it better? match
-> if let
doesn't really give us much, it's still nested code.
Ideally, I'd like to see something like this? Not tested though:
let app_file = LDNApplication::load_from_db(id, owner, repo).await.map_err(ErrorNotFound)?;
let body = serde_json::to_string_pretty(&app_file).map_err(ErrorInternalServerError)?;
HttpResponse::Ok().body(body)
https://docs.rs/actix-web/latest/actix_web/error/fn.ErrorNotFound.html
https://docs.rs/actix-web/latest/actix_web/error/fn.ErrorInternalServerError.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applies to other instances in this PR as well.
No description provided.