Commit dae6c2ed authored by Célande Adrien's avatar Célande Adrien Committed by Vincent A

[ing] handle new recipient errors

I handle new recipient errors.
Now the website return a 400 error with its errors.
So the handle_error pages are useless.
parent c654eec8
......@@ -30,9 +30,7 @@ from weboob.browser.pages import LoggedPage, JsonPage
from weboob.browser.elements import method, DictElement, ItemElement
from weboob.browser.filters.json import Dict
from weboob.browser.filters.standard import Env, Field, Date
from import (
Recipient, RecipientInvalidIban, RecipientInvalidOTP,
from import Recipient
class TransferINGVirtKeyboard(SimpleVirtualKeyboard):
......@@ -168,13 +166,6 @@ class AddRecipientPage(LoggedPage, JsonPage):
rcpt = self.doc
return rcpt['accountHolderName'] == recipient.label and rcpt['iban'] == recipient.iban
def handle_error(self):
if 'error' in self.doc:
if self.doc['error']['code'] == 'EXTERNAL_ACCOUNT.IBAN_NOT_FRENCH':
# not using the bank message because it is too generic
raise RecipientInvalidIban(message="L'IBAN doit correpondre à celui d'une banque domiciliée en France.")
assert False, 'Recipient error not handled'
class OtpChannelsPage(LoggedPage, JsonPage):
def get_sms_info(self):
......@@ -186,10 +177,4 @@ class OtpChannelsPage(LoggedPage, JsonPage):
class ConfirmOtpPage(LoggedPage, JsonPage):
def handle_error(self):
if 'error' in self.doc:
error_code = self.doc['error']['code']
if error_code == 'SCA.WRONG_OTP_ATTEMPT':
raise RecipientInvalidOTP(message=self.doc['error']['message'])
assert False, 'Recipient OTP error not handled'
......@@ -30,7 +30,7 @@ from weboob.browser.exceptions import ClientError
from import (
TransferBankError, TransferInvalidAmount,
AddRecipientStep, RecipientInvalidOTP,
AddRecipientTimeout, AddRecipientBankError,
AddRecipientTimeout, AddRecipientBankError, RecipientInvalidIban,
from import FrenchTransaction
from import Value
......@@ -436,23 +436,38 @@ class IngAPIBrowser(LoginBrowser, StatesMixin):
raise AddRecipientStep(recipient, Value('code', label='Veuillez saisir le code temporaire envoyé par SMS'))
def handle_recipient_error(self, r):
# The bank gives an error message when an error occures.
# But sometimes the message is not relevant.
# So I may replace it by nothing or by a custom message.
# The exception to raise can be coupled with:
# * Nothing: empty message
# * None: message of the bank
# * String: custom message
'EXTERNAL_ACCOUNT.EXTERNAL_ACCOUNT_IS_INTERNAL_ACCOUT': (AddRecipientBankError, None), # nice spelling
'EXTERNAL_ACCOUNT.IBAN_NOT_FRENCH': (RecipientInvalidIban, "L'IBAN doit correpondre à celui d'une banque domiciliée en France."),
'SCA.WRONG_OTP_ATTEMPT': (RecipientInvalidOTP, None),
'INPUT_INVALID': (AssertionError, None), # invalid request
error_page = r.response.json()
if 'error' in error_page:
error = error_page['error']
# the error message may seem generic
# but after testing multiple cases
# it is the only time that it appears
raise AddRecipientTimeout()
elif error['code'] in (
# not allowed to add a recipient
raise AddRecipientBankError(message=error['message'])
error_exception = RECIPIENT_ERROR.get(error['code'])
if error_exception:
if len(error_exception) == 1:
raise error_exception[0]()
elif error_exception[1] is None:
raise error_exception[0](message=error['message'])
raise error_exception[0](message=error_exception[1])
assert False, 'Recipient error not handled'
assert False, 'Recipient error "%s" not handled' % error['code']
def end_sms_recipient(self, recipient, code):
......@@ -477,8 +492,6 @@ class IngAPIBrowser(LoginBrowser, StatesMixin):
def new_recipient(self, recipient, **params):
......@@ -507,8 +520,6 @@ class IngAPIBrowser(LoginBrowser, StatesMixin):
assert, "The recipients don't match."
self.add_recipient_info =
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment