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

chore: when use match pattern, we use result as variable name in the success path #31

Open
EiffelFly opened this issue Feb 13, 2023 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@EiffelFly
Copy link
Owner

Context

Currently, we use this match pattern in our backend

let discord_message =
        match db_third_party::discord::DiscordMessage::create(client, &payload).await {
            Ok(discord_message) => discord_message,
            Err(error) => {
                return Err((
                    StatusCode::INTERNAL_SERVER_ERROR,
                    format!(
                        "Something went wrong when create discord message: {}",
                        error
                    ),
                )
                    .into_response())
            }
        };

In order to reduce the overhead of coming up a variable name for Ok(), I purpose that we unify that as below

let discord_message =
        match db_third_party::discord::DiscordMessage::create(client, &payload).await {
            Ok(result) => result,
            Err(error) => {
                return Err((
                    StatusCode::INTERNAL_SERVER_ERROR,
                    format!(
                        "Something went wrong when create discord message: {}",
                        error
                    ),
                )
                    .into_response())
            }
        };

Instead of coming up a new name, we use result

@EiffelFly EiffelFly added enhancement New feature or request good first issue Good for newcomers labels Feb 13, 2023
@EiffelFly EiffelFly changed the title chore: refactor how we use match chore: when use match pattern, we use result as variable name in the success path Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant