juspay/hyperswitch

[REFACTOR]: [Payu] Remove Default Case Handling

Open

#3,238 opened on Jan 4, 2024

View on GitHub
 (2 comments) (0 reactions) (1 assignee)Rust (4,676 forks)batch import
A-connector-integrationC-refactorhelp wanted

Repository metrics

Stars
 (42,690 stars)
PR merge metrics
 (Avg merge 6d 22h) (213 merged PRs in 30d)

Description

:memo: Feature Description

  • We utilize match statements to make pivotal decisions, such as generating requests based on the payment method type and managing responses received from the connector.
  • These conditions generally go hand in hand with enum variants.
  • Default case is used because a match statement needs to be exhaustive i.e. every variant needs to be covered.
  • So, if all the explicit cases are handled then default is used to handle the rest.
  • Each connector have these match statements but many of them don’t provide reference to each variant in their default case, rather a _ is put to handle all the other cases.
  • This approach carries a risk because developers may inadvertently overlook the need for explicit handling of the new cases.

:hammer: Possible Implementation

  • Instead of relying on a default match case _, developers should handle each and every variant explicitly.
  • By doing so, if there are any changes in the future, they can readily assess the impact of their modifications simply by compiling the code.
  • In order to manage payment methods that are not implemented by Hyperswitch or yet to be implemented, the connector transformers file should make use of the NotImplemented ConnectorError enum variant.
  • By doing so, we will throw same error message for all the Connector Implementation
  • You can check this PR for further reference https://github.com/juspay/hyperswitch/pull/1955

:bookmark: Note: All the changes needed should be contained within hyperswitch/crates/router/src/connector/payu/transformer.rs

:package: Have you spent some time checking if this feature request has been raised before?

  • I checked and didn't find a similar issue

:package: Have you read the Contributing Guidelines?

:sparkles: Are you willing to submit a PR?

Contributor guide