kraffslol / react-native-braintree-xplat

Cross-platform Braintree module for React Native
MIT License
81 stars 121 forks source link

getCardNonce causes an app crash on iOS when an error message is returned #91

Open craigcartmell opened 6 years ago

craigcartmell commented 6 years ago

Issue Calling getCardNonce on an iOS device causes the full app to crash when an error message is returned from the request.

This appears to be an error in the way the library is attempting to serialise the response from the getCardNonce request.

Maybe it needs to use NSJSONSerialization isValidObject (Disclaimer, I'm no objective-c expert)?

Step to replicate Send any invalid data to BTClient.getCardNonce(), e.g. an empty object or invalid card number.

Versions react-native@0.53.3 react-native-braintree-xplat@4.0.0

Stacktrace

 Uncaught exception: Invalid type in JSON write (NSHTTPURLResponse)
2018-04-05 11:32:13.439544+0100 ed4[412:78845] invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific - break on _CFRunLoopError_RunCalledWithInvalidMode to debug. This message will only appear once per execution.
2018-04-05 11:32:14.320270+0100 ed4[412:80350] [] nw_connection_get_connected_socket 147 Connection has no connected handler
2018-04-05 11:32:14.320389+0100 ed4[412:80350] TCP Conn 0x1cc171f40 Failed : error 0:61 [61]
2018-04-05 11:32:18.439619+0100 ed4[412:78845] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (NSHTTPURLResponse)'
*** First throw call stack:
(0x184b66d8c 0x183d205ec 0x184b66c6c 0x18563c8d4 0x18563eb40 0x184ba4654 0x18563e11c 0x18563c584 0x18563d5d4 0x1010c9e00 0x10119f5d0 0x1011968dc 0x1026c1260 0x1026c1220 0x1026c5db0 0x184b0f070 0x184b0cbc8 0x184a2cda8 0x186a0f020 0x18ea0d78c 0x100b30b18 0x1844bdfc0)
libc++abi.dylib: terminating with uncaught exception of type NSException
craigcartmell commented 6 years ago

Example of response which we're attempting to JSON serialise:

{
  BTCustomerInputBraintreeValidationErrorsKey =     {
    error =         {
      message = "Credit card is invalid";
};
  fieldErrors =         (
    {
      field = creditCard;
  fieldErrors =                 (
    {
      code = 81703;
  field = number;
  message = "Credit card type is not accepted by this merchant account";
}
);
}
);
};
craigcartmell commented 6 years ago

Feel free to use https://github.com/craigcartmell/react-native-braintree-xplat/commit/32a25239a99d2453db3064cf530120457f7ed252 if you're finding the same issue and are desperate for a solution.

It will just return a single failure string, e.g. Credit card type is not accepted by this merchant account

Talkwondo commented 6 years ago

+1

paul-apacio commented 5 years ago

+1