awslabs / aws-mobile-appsync-sdk-js

JavaScript library files for Offline, Sync, Sigv4. includes support for React Native
Apache License 2.0
921 stars 266 forks source link

How does subscription handle error? #571

Open zhaoyi0113 opened 4 years ago

zhaoyi0113 commented 4 years ago

I have below code in nodejs. It works well. But I can't get any error even I specify an invalid URL or wrong authentication. I wonder how subscription report errors.

const createClient = (url: string, auth: any) => {
  const client = new AWSAppSyncClient({
    url,
    region: 'ap-southeast-2',
    auth,
    disableOffline: true,
    offlineConfig: {
      callback: (err, succ) => {
        if (err) console.error(err);
        else {
          console.log('SUCCESS', succ);
        }
      },
    },
  });
  return client;
};

const client = createClient(URL, oidcAuth);
client
    .hydrated()
    .then((gq) => {
      gq.subscribe({
      query: subscribeTxn,
      fetchPolicy: 'network-only',
      variables: { id: '123' },
    })
    .subscribe({
      next: (data: any) => {
        console.log('realtime data: ', data);
      },
      complete: () => {
        console.log('complete');
      },
      error: (err: Error) => console.error(err),
    });
    })