I'm wrapping an imported SDK class with a Proxy so that I can eventually catch RequestExceptions, i.e. when there is no network connection to display error popups.
The app is working without issues in remote debugging mode, however, when I disable it the error Can't find Variable: Proxy
is thrown. Do I need to import this explicitly somehow? Or is there an alternative method to wrap a class so that I can catch all of its exceptions?
Below is the code for the Proxy wrapper.
import Backend from 'backend-sdk'; import RequestException from 'backend-sdk/src/exceptions/RequestException'; let handler = { get: (target, name, receiver) => { try { return Reflect.get(target, name, receiver); } catch (e) { if (e instanceof RequestException) { console.error(e); //TODO Add a toast notification for failed API requests } else { throw e; } } } }; export default new Proxy(new Backend(), handler);
Proxy is not pollyfilled in react native by default. It works in chrome debugger because react native uses chrome js engine during debugging see Document on js environment. You may try using Proxy pollyfill.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With