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

Merged
merged 1 commit into from
Jan 14, 2025

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.

@Filip-L Filip-L force-pushed the FIL-461-try-to-get-rid-of-the-matches branch from f746860 to 6b49281 Compare January 14, 2025 10:17
@Filip-L Filip-L temporarily deployed to production-fidl January 14, 2025 10:17 — with GitHub Actions Inactive
@Filip-L Filip-L merged commit e2e7ab4 into main Jan 14, 2025
4 checks passed
@Filip-L Filip-L deleted the FIL-461-try-to-get-rid-of-the-matches branch January 14, 2025 10:20
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