Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ES6 Proxy not defined in React Native when not in remote debug mode?

Tags:

react-native

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);
like image 570
Mastergalen Avatar asked Aug 10 '16 10:08

Mastergalen


1 Answers

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.

like image 74
while1 Avatar answered Sep 30 '22 23:09

while1