Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Filip-L
Copy link
Collaborator

@Filip-L Filip-L commented Dec 31, 2024

No description provided.

Comment on lines 25 to 35
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()),
}
}
Copy link
Collaborator

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

Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants