Created
October 2, 2012 00:39
-
-
Save ajsharp/3815488 to your computer and use it in GitHub Desktop.
Handling a 409 response when attempting to create a balanced account and a user with that email account already exists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| begin | |
| balanced_account = Balanced::Marketplace.my_marketplace.create_merchant(email, merchant_hash, bank_account_uri, name) | |
| rescue Balanced::Error => ex | |
| if ex.response[:status] == 409 | |
| # A 409 is returned if the account has already been created. | |
| # Balanced will return the account uri in the error response, so we simply need to | |
| # create an internal account on our end. | |
| decoded_body = ex.response[:body] | |
| uri = decoded_body['extras']['account_uri'] | |
| begin | |
| # lookup the existing balanced account object | |
| balanced_account = Balanced::Account.find(uri) | |
| rescue | |
| # this really shouldn't happen... | |
| raise "Could not find Balanced account with uri => #{uri}" | |
| end | |
| else | |
| # re-raise other exceptions | |
| raise ex | |
| end | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FWIW, the balanced API will return a 409 status code in the same case (duplicate email address) when attempting to create a buyer as well.