guyzyl / whatsapp-contact-sync

Easy way to sync between the contact photos on WhatsApp to Google Contacts
https://whasync.com/
Other
187 stars 23 forks source link

Add error handling for failed contact loading in sync.ts #158

Closed guyzyl closed 6 months ago

guyzyl commented 6 months ago

This should handle the following error (causing the backend to crash):

/app/server/node_modules/gaxios/build/src/gaxios.js:142
                throw new common_1.GaxiosError(`Request failed with status code ${translatedResponse.status}`, opts, translatedResponse);
                      ^
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {"
    at Gaxios._request (/app/server/node_modules/gaxios/build/src/gaxios.js:142:23)
"GaxiosError: Login Required.
  config: {
    url: 'https://people.googleapis.com/v1/people/me/connections?pageSize=250&personFields=names%2CemailAddresses%2CphoneNumbers%2Cphotos&pageToken=',
    method: 'GET',
    userAgentDirectives: [
      {
        product: 'google-api-nodejs-client',
        version: '7.0.1',
        comment: 'gzip'
      }
    ],
    paramsSerializer: [Function (anonymous)],
    headers: {
      'x-goog-api-client': 'gdcl/7.0.1 gl-node/21.7.3',
      'Accept-Encoding': 'gzip',
      'User-Agent': 'google-api-nodejs-client/7.0.1 (gzip)'
    },
    params: {
      pageSize: 250,
      personFields: 'names,emailAddresses,phoneNumbers,photos',
      pageToken: ''
    },
    validateStatus: [Function (anonymous)],
    retry: true,
    responseType: 'unknown',
    errorRedactor: [Function: defaultErrorRedactor],
    retryConfig: {
      currentRetryAttempt: 0,
      retry: 3,
      httpMethodsToRetry: [ 'GET', 'HEAD', 'PUT', 'OPTIONS', 'DELETE' ],
      noResponseRetries: 2,
      statusCodesToRetry: [ [ 100, 199 ], [ 429, 429 ], [ 500, 599 ] ]
    }
  },
  response: {
    config: {
      url: 'https://people.googleapis.com/v1/people/me/connections?pageSize=250&personFields=names%2CemailAddresses%2CphoneNumbers%2Cphotos&pageToken=',
      method: 'GET',
      userAgentDirectives: [
        {
          product: 'google-api-nodejs-client',
          version: '7.0.1',
          comment: 'gzip'
        }
      ],
      paramsSerializer: [Function (anonymous)],
      headers: {
        'x-goog-api-client': 'gdcl/7.0.1 gl-node/21.7.3',
        'Accept-Encoding': 'gzip',
        'User-Agent': 'google-api-nodejs-client/7.0.1 (gzip)'
      },
      params: {
        pageSize: 250,
        personFields: 'names,emailAddresses,phoneNumbers,photos',
        pageToken: ''
      },
      validateStatus: [Function (anonymous)],
      retry: true,
      responseType: 'unknown',
      errorRedactor: [Function: defaultErrorRedactor]
    },
    data: {
      error: {
        code: 401,
        message: 'Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.',
        errors: [
          {
            message: 'Login Required.',
            domain: 'global',
            reason: 'required',
            location: 'Authorization',
            locationType: 'header'
          }
        ],
        status: 'UNAUTHENTICATED',
        details: [
          {
            '@type': 'type.googleapis.com/google.rpc.ErrorInfo',
            reason: 'CREDENTIALS_MISSING',
            domain: 'googleapis.com',
            metadata: [Object]
          }
        ]
      }
    },
    headers: {
      'alt-svc': 'h3=":443"; ma=2592000',
      'cache-control': 'private',
      'content-encoding': 'gzip',
      'content-type': 'application/json; charset=UTF-8',
      date: 'Fri, 26 Apr 2024 01:24:40 GMT',
      server: 'ESF',
      'transfer-encoding': 'chunked',
      vary: 'Origin, X-Origin, Referer',
      'www-authenticate': 'Bearer realm="https://accounts.google.com/"',
      'x-content-type-options': 'nosniff',
      'x-frame-options': 'SAMEORIGIN',
      'x-xss-protection': '0'
    },
    status: 401,
    statusText: 'Unauthorized',
    request: {
      responseURL: 'https://people.googleapis.com/v1/people/me/connections?pageSize=250&personFields=names%2CemailAddresses%2CphoneNumbers%2Cphotos&pageToken='
    }
  },
  error: undefined,
  status: 401,
  code: 401,
  errors: [
    {
      message: 'Login Required.',
      domain: 'global',
      reason: 'required',
      location: 'Authorization',
      locationType: 'header'
    }
  ],
  [Symbol(gaxios-gaxios-error)]: '6.2.0'
}