diff --git a/fints/client.py b/fints/client.py index 213972a..95411c8 100644 --- a/fints/client.py +++ b/fints/client.py @@ -1608,7 +1608,14 @@ def _process_response(self, dialog, segment, response): # Fail-safe block all further attempts with this PIN if self.pin: self.pin.block() - raise FinTSClientPINError("Error during dialog initialization, PIN wrong?") + error = FinTSClientPINError( + "Error during dialog initialization, PIN wrong? Bank response: {} - {}".format( + response.code, response.text + ) + ) + error.response_code = response.code + error.response_text = response.text + raise error if response.code == '3938': # Account locked, e.g. after three wrong password attempts. Theoretically, the bank might allow us to diff --git a/tests/test_client.py b/tests/test_client.py index f602e4f..9fbdf99 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -37,10 +37,16 @@ def test_pin_wrong(fints_server): fints_server, product_id="TEST-123", product_version="1.2.3", ) - with pytest.raises(FinTSClientPINError): + with pytest.raises(FinTSClientPINError) as excinfo: with client: pass + # The bank's own response is passed on, since the error is raised for + # any 9xxx code during initialization and not only for a wrong PIN. + assert excinfo.value.response_code == '9910' + assert excinfo.value.response_text.startswith('Pin ung') + assert '9910' in str(excinfo.value) + assert client.pin.blocked with pytest.raises(Exception):