Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error/fail handling #15

Closed
gastonmorixe opened this issue Jan 16, 2016 · 12 comments · Fixed by #24
Closed

Better error/fail handling #15

gastonmorixe opened this issue Jan 16, 2016 · 12 comments · Fixed by #24

Comments

@gastonmorixe
Copy link

Hey, awesome work here!

In my fork (branch stranger) I added this to get more information at failing time. Otherwise if the user cancel or something else happen, I can't hide HUDs or react in the UI in any way.

switch (transaction.error.code) {
    case SKErrorUnknown:
        callback(@[@"transaction_failed_unknown"]);
        break;
    case SKErrorClientInvalid:
        callback(@[@"transaction_failed_client_invalid"]);
        break;
    case SKErrorPaymentCancelled:
        callback(@[@"transaction_failed_payment_cancelled"]);
        break;
    case SKErrorPaymentInvalid:
        callback(@[@"transaction_failed_payment_invalid"]);
        break;
    case SKErrorPaymentNotAllowed:
        callback(@[@"transaction_failed_payment_not_allowed"]);
        break;
    case SKErrorStoreProductNotAvailable:
        callback(@[@"transaction_failed_store_product_not_available"]);
        break;
    case SKErrorCloudServicePermissionDenied:
        callback(@[@"transaction_failed_cloud_service_permission_denied"]);
        break;
    case SKErrorCloudServiceNetworkConnectionFailed:
        callback(@[@"transaction_failed_cloud_service_network_connection_failed"]);
        break;

    default:
        break;
}
@chirag04
Copy link
Owner

Can you PR?

@gastonmorixe
Copy link
Author

No time sorry :( Feel to patch it with that

@agolovenko
Copy link

+1 vote to promote this peace of code to the main branch

@grabbou
Copy link

grabbou commented Mar 13, 2016

You should use RCTJSErrorFromNSError from RCTUtils.h that will convert all these errors for you automatically.

@transitive-bullshit
Copy link

See #21. @grabbou it wasn't obvious how to use RCTJSErrorFromNSError here but feel free to create an alternative PR with a cleaner solution.

@DenisIzmaylov
Copy link
Contributor

@chirag04 Could you please merge that?

@chirag04
Copy link
Owner

@DenisIzmaylov waiting for @fisch0920 to update the PR as per @grabbou's feedback.

@grabbou
Copy link

grabbou commented Apr 25, 2016

BTW can we try to use RCTConvert ? I am wondering if it will work the other way (when value is sent from native to JS). When value is sent from JS to native, you can do this:
https://github.com/grabbou/react-native/blob/feature/tab-bar-position/React/Views/RCTTabBarManager.m#L15-L23

@DenisIzmaylov
Copy link
Contributor

May be we can do it ourselves?

@DenisIzmaylov
Copy link
Contributor

DenisIzmaylov commented Apr 27, 2016

It looks not informant still (PaymentCancelled error example):

2016-04-27 16:46:58.873 [error][tid:com.facebook.react.JavaScript] { code: 'ESKERRORDOMAIN2',
  message: 'Cannot connect to iTunes Store',
  nativeStackIOS: 
   [ '0   Mentor2                             0x00000001000ba474 RCTJSErrorFromCodeMessageAndNSError + 148',
     '1   Mentor2                             0x00000001000ba3a0 RCTJSErrorFromNSError + 264',
     '2   Mentor2                             0x000000010014cf54 -[InAppUtils paymentQueue:updatedTransactions:] + 596',
     '3   StoreKit                            0x000000018ca2ca6c <redacted> + 104',
     '4   CoreFoundation                      0x0000000181c0073c CFArrayApplyFunction + 68',
     '5   StoreKit                            0x000000018ca2c9e8 <redacted> + 148',
     '6   StoreKit                            0x000000018ca2d4f0 <redacted> + 1244',
     '7   StoreKit                            0x000000018ca2dff8 <redacted> + 144',
     '8   StoreKit                            0x000000018ca2c898 <redacted> + 152',
     '9   libdispatch.dylib                   0x00000001005e1a7c _dispatch_call_block_and_release + 24',
     '10  libdispatch.dylib                   0x00000001005e1a3c _dispatch_client_callout + 16',
     '11  libdispatch.dylib                   0x00000001005e74e4 _dispatch_main_queue_callback_4CF + 2096',
     '12  CoreFoundation                      0x0000000181cd8dd8 <redacted> + 12',
     '13  CoreFoundation                      0x0000000181cd6c40 <redacted> + 1628',
     '14  CoreFoundation                      0x0000000181c00d10 CFRunLoopRunSpecific + 384',
     '15  GraphicsServices                    0x00000001834e8088 GSEventRunModal + 180',
     '16  UIKit                               0x0000000186ecdf70 UIApplicationMain + 204',
     '17  Mentor2                             0x0000000100021034 main + 124',
     '18  libdyld.dylib                       0x000000018179e8b8 <redacted> + 4' ],
  domain: 'SKErrorDomain' }

We should you index of this enum:
https://developer.apple.com/library/ios/documentation/StoreKit/Reference/StoreKitTypes/index.html#//apple_ref/doc/constant_group/Store_Kit_Errors

It looks a little bit weird.

@mcrowe
Copy link

mcrowe commented Jul 6, 2016

As @DenisIzmaylov mentioned, the error codes are very difficult to work with now. I used the following map to make them usable in my codebase:

// Mapping from error codes returned by In-App-Utils to Apple's StoreKit errors.
// See: https://developer.apple.com/documentation/storekit/skerror.code
// NOTE: RCTJSErrorFromNSError prepends ESKERRORDOMAIN to make errors unique across
//       iOS domains.
var STORE_KIT_ERRORS = {
  ESKERRORDOMAIN0: 'unknown',
  ESKERRORDOMAIN1: 'client_invalid',
  ESKERRORDOMAIN2: 'payment_canceled',
  ESKERRORDOMAIN3: 'payment_invalid',
  ESKERRORDOMAIN4: 'payment_not_allowed',
  ESKERRORDOMAIN5: 'store_product_not_available',
  ESKERRORDOMAIN6: 'cloud_service_permission_denied',
  ESKERRORDOMAIN7: 'cloud_service_network_connection_failed',
  ESKERRORDOMAIN8: 'unknown'
};

Something like this should be added to this library. I'm not interested in creating a PR at this time, though.

@kevinpumpup
Copy link

Updated link for SKError.Code: https://developer.apple.com/documentation/storekit/skerror.code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants