miragejs: Passthrough is resulting in error in native code for react native

Hi,

I was trying to setup mirage in a react native application as shown below for development using API stubs Since I am integrating mirage in an existing application, I am using pass through to allow the API calls which are available in the backend already.

export function makeServer({environment = 'development'} = {}) {
return createServer({
    routes() {
      this.logging = true;
      this.get(
        `https://my_server/groups`,
        () => {
          return {
            "groupName": "GROUP_NAME"
          };
        }
      );
      //this.passthrough();
      this.passthrough('https://codepush.appcenter.ms/**');
      this.passthrough('https://my_server/**');
    }
  });
}

We are seeing the below error when an API call goes through passthrough which is resulting in a Native exception and a failure of the API call

Mirage: Passthrough request for GET https://codepush.appcenter.ms/v0.1/public/codepush/update_check
ReactNative: Exception in native call
    java.lang.NullPointerException: Attempt to invoke virtual method 'double java.lang.Double.doubleValue()' on a null object reference
        at com.facebook.react.bridge.ReadableNativeArray.getDouble(ReadableNativeArray.java:91)
        at com.facebook.react.bridge.JavaMethodWrapper$4.extractArgument(JavaMethodWrapper.java:63)
        at com.facebook.react.bridge.JavaMethodWrapper$4.extractArgument(JavaMethodWrapper.java:59)
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:355)
        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:150)
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:26)
        at android.os.Looper.loop(Looper.java:216)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:225)
        at java.lang.Thread.run(Thread.java:764)

React Native: 0.61.2 MirageJS: 0.1.41

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 7
  • Comments: 15 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Ok everyone, I found the reason for this error. It took waaaaay longer than I expected but I found the root cause. Please refer to this PR in the Pretender repo. It’d be awesome if this got expedited so feel free to reach out to those necessary to review it.

I must say I learned a lot, and kinda proud I found this, my first bug fix on a public project. 😅

gold1 3

Same as above. Works on iOS, fails on Android with the Java error already cited.

Mirage 0.1.41 RN 0.63.4

I think the path forward here would be to add a server.handle method (which we had started in https://github.com/miragejs/miragejs/pull/699/files) so you could wire up mirage with different interceptors, like msw or even express. I’m not actively maintaining mirage atm but refactoring away from pretender would be a good next step towards solving this.

same issue here. any solution?