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

Expo: A networking error occurred during POST request #19

Open
spsaucier opened this issue Jan 29, 2025 · 0 comments
Open

Expo: A networking error occurred during POST request #19

spsaucier opened this issue Jan 29, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@spsaucier
Copy link

When I try to initialize Statsig using the Expo client, I'm getting the error specified here: https://github.com/statsig-io/js-client-monorepo/blob/main/packages/client-core/src/NetworkCore.ts#L270

ERROR  [Statsig] A networking error occurred during POST request to https://featureassets.org/v1/initialize?k=client-MY_CLIENT_KEY&st=javascript-client-expo&sv=3.10.0&t=1738103586633&sid=474fe0de-873f-41b1-bf50-0d5f71814139&se=1. TypeError: Network request failed [TypeError: Network request failed]
ERROR  [Statsig] A networking error occurred during POST request to https://prodregistryv2.org/v1/rgstr?k=client-MY_CLIENT_KEY&st=javascript-client-expo&sv=3.10.0&t=1738103591179&sid=474fe0de-873f-41b1-bf50-0d5f71814139&ec=2. TypeError: Network request failed [TypeError: Network request failed]
WARN  [Statsig] Failed to flush events.
ERROR  [Statsig] A networking error occurred during POST request to https://prodregistryv2.org/v1/rgstr?k=client-MY_CLIENT_KEY&st=javascript-client-expo&sv=3.10.0&t=1738103591184&sid=474fe0de-873f-41b1-bf50-0d5f71814139&ec=1. TypeError: Network request failed [TypeError: Network request failed]
WARN  [Statsig] Failed to flush events.
ERROR  [Statsig] A networking error occurred during POST request to https://prodregistryv2.org/v1/rgstr?k=client-MY_CLIENT_KEY&st=javascript-client-expo&sv=3.10.0&t=1738103601004&sid=474fe0de-873f-41b1-bf50-0d5f71814139&ec=2. TypeError: Network request failed [TypeError: Network request failed]
WARN  [Statsig] Failed to flush events.

The Expo docs mention that some users experienced a networking error before SDK version 3.1.0, but I am experiencing it on 3.11.0 as well: https://docs.statsig.com/client/javascript-sdk/expo#network-issues
"@statsig/expo-bindings": "^3.11.0",

My provider:

import React, { PropsWithChildren, useEffect, useState } from 'react';
import { MMKV } from 'react-native-mmkv';
import { StatsigProviderExpo } from '@statsig/expo-bindings';

import { useFacilityProvider } from 'app/scan/components/Facilities/JoinFacilityProvider';

import { BREADCRUMB_TYPES } from '../config/enums';
import { getAppVersion, getEnvVar } from '../util/env';
import { logBreadcrumb, logError } from '../util/monitorClient';
import { useAuth } from './AuthProvider';

export const StatsigProvider = ({ children }: PropsWithChildren<any>) => {
  const { user } = useAuth();
  const { facility } = useFacilityProvider();
  const [storageProvider] = useState(() => {
    const mmkv = new MMKV();
    return {
      isReady: () => true,
      isReadyResolver: () => null,
      getProviderName: () => 'MMKV',
      getAllKeys: () => mmkv.getAllKeys(),
      getItem: (key: string) => mmkv.getString(key) ?? null,
      setItem: (key: string, value: string) => mmkv.set(key, value),
      removeItem: (key: string) => mmkv.delete(key),
    };
  });

  // Log errors if user or facility data is missing
  useEffect(() => {
    if (!user) {
      logError('Statsig error: No user data available', {
        source: 'StatsigProvider',
      });
    }
    if (!facility) {
      logError('Statsig error: No facility data available', {
        source: 'StatsigProvider',
        ...user,
      });
    }
  }, [user, facility]);

  useEffect(() => {
    if (user) {
      logBreadcrumb('Statsig: User updated', BREADCRUMB_TYPES.log, {
        userID: user._id,
        email: user.email,
        facilityId: facility?.facilityId,
      });
    }
  }, [user, facility]);

  return (
    <StatsigProviderExpo
      sdkKey={getEnvVar('STATSIG_KEY') || ''}
      options={{
        storageProvider,
        environment: {
          tier: getEnvVar('ENVIRONMENT'),
        },
      }}
      user={{
        userID: user?._id || '',
        email: user?.email || '[email protected]',
        locale: user?.market,
        appVersion: getAppVersion(),
        custom: user
          ? {
              appLanguage: user.appLanguage,
              deviceId: user.deviceId,
              deviceManufacturer: user.deviceManufacturer,
              deviceModel: user.deviceModel,
              facilities: user.facilities,
              platform: user.platform,
              platformVersion: user.platformVersion,
              name: user.name,
              userAgent: 'FMA',
            }
          : undefined,
        customIDs: facility?.facilityId
          ? {
              facilityId: facility.facilityId,
            }
          : undefined,
      }}
    >
      {children}
    </StatsigProviderExpo>
  );
};
@linear linear bot added the bug Something isn't working label Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant