0

I am trying to build an application where vpn connection plays a critical role so if a user disconnects from its vpn i would like to keep try to query or try to apply edit to feature layer if vpn somehow gets connected again. Here is that i have tried so far

    const testFeatureLayer = new FeatureLayer({ url: LAYERDETAILS.TEST.url})
    var query = testFeatureLayer.createQuery();
    query.where = '1=1'
    query.outFields = ['*']
    from(testFeatureLayer.queryFeatures(query)).pipe(
      retry({
        count:50,
        delay: 1000, // 2 second delay between retries
        resetOnSuccess: true
      }),
      catchError((error) => {
        console.error('Failed after all retries:', error);
        return throwError(() => error);
      })
    ).subscribe({
      next: (response) => {
        console.log('Query response:', response);
      },
      error: (error) => {
        console.error('Final error:', error);
      }
    });

Here is Esri Feature Layer; https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html

This method query features - > (method) __esri.FeatureLayer.queryFeatures(query?: __esri.Query | __esri.QueryProperties, options?: __esri.FeatureLayerQueryFeaturesOptions): Promise<__esri.FeatureSet>

I have tried doing it with from, or with of but i got not luck.

1 Answer 1

0

Okay so, i was able to come up with a code like this not sure if its best way to do it but this does it for now, if anyone wants to improve it please be my guest i would really appreciate it.

  async retryEsriLayer(): Promise<any> {
let retryCount = 0;
const maxRetries = 50;
while (retryCount < maxRetries) {
  try {
    const testFeatureLayer = new FeatureLayer({ url: LAYERDETAILS.SUREC_W_USERS.url })
    var query = testFeatureLayer.createQuery();
    query.where = '1=1'
    query.outFields = ['*']

    const result = await lastValueFrom(
      from(testFeatureLayer.queryFeatures(query)).pipe(
        catchError((error) => {

          console.error(`Error during query attempt ${retryCount + 1}:`, error);
          throw error;
        })
      )
    );
    return result;
  }
  catch (error) {
    retryCount++;
    console.warn(`Retry ${retryCount} failed. Retrying...`);

    if (retryCount >= maxRetries) {
      console.error('Max retries reached:', error);
      throw error;
    }

    await new Promise(res => setTimeout(res, 2000));
  }
}

}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.