google-api-nodejs-client icon indicating copy to clipboard operation
google-api-nodejs-client copied to clipboard

gmail.users.watch() - Same call returns 500 & 200

Open e1um opened this issue 7 years ago • 4 comments

Environment details

  • OS: macOS Mojave 10.14.3
  • Node.js version: 10.0.0
  • npm version:6.9.0
  • googleapis version:^33.0.0

Steps to reproduce

  1. Initialize gmail libarary
google.gmail({version: 'v1', auth}
  1. Set params for call
const watchReq = {
    labelIds: [
      'CATEGORY_UPDATES',
      'DRAFT',
      'CATEGORY_PROMOTIONS',
      'CATEGORY_SOCIAL',
      'CATEGORY_FORUMS',
      'TRASH',
      'CHAT',
      'SPAM',
    ],
    labelFilterAction: 'exclude',
    topicName: '**************',

const params = {
  userId:'me', 
  requestBody: watchReq
}

gmail.users.watch(params)
  1. Response
response:
   { status: 500,
     statusText: 'Internal Server Error',
     headers:
      { vary: 'Origin, X-Origin',
        'content-type': 'application/json; charset=UTF-8',
        date: 'Fri, 15 Mar 2019 16:14:15 GMT',
        expires: 'Fri, 15 Mar 2019 16:14:15 GMT',
        'cache-control': 'private, max-age=0',
        'x-content-type-options': 'nosniff',
        'x-frame-options': 'SAMEORIGIN',
        'x-xss-protection': '1; mode=block',
        server: 'GSE',
        'alt-svc': 'quic=":443"; ma=2592000; v="46,44,43,39"',
        connection: 'close',
        'transfer-encoding': 'chunked' },
     config:
      { adapter: [Function: httpAdapter],
        transformRequest: [Object],
        transformResponse: [Object],
        timeout: 0,
        xsrfCookieName: 'XSRF-TOKEN',
        xsrfHeaderName: 'X-XSRF-TOKEN',
        maxContentLength: 2147483648,
        validateStatus: [Function],
        headers: [Object],
        method: 'post',
        url: 'https://www.googleapis.com/gmail/v1/users/me/watch',
        paramsSerializer: [Function],
        data: '{"labelIds":["CATEGORY_UPDATES","DRAFT","CATEGORY_PROMOTIONS","CATEGORY_SOCIAL","CATEGORY_FORUMS","TRASH","CHAT","SPAM"],"labelFilterAction":"exclude","topicName":"******************"}',
        params: {} },
     request:
      ClientRequest {
        _events: [Object],
        _eventsCount: 6,
        _maxListeners: undefined,
        output: [],
        outputEncodings: [],
        outputCallbacks: [],
        outputSize: 0,
        writable: true,
        _last: true,
        chunkedEncoding: false,
        shouldKeepAlive: false,
        useChunkedEncodingByDefault: true,
        sendDate: false,
        _removedConnection: false,
        _removedContLen: false,
        _removedTE: false,
        _contentLength: null,
        _hasBody: true,
        _trailer: '',
        finished: true,
        _headerSent: true,
        socket: [TLSSocket],
        connection: [TLSSocket],
        _header: 'POST /gmail/v1/users/me/watch HTTP/1.1\r\nAccept: application/json, text/plain, */*\r\nContent-Type: application/json;charset=utf-8\r\nAccept-Encoding: gzip\r\nUser-Agent: google-api-nodejs-client/0.2.1 (gzip)\r\nAuthorization: Bearer **************\r\nContent-Length: 210\r\nHost: www.googleapis.com\r\nConnection: close\r\n\r\n',
        _onPendingData: [Function: noopPendingOutput],
        agent: [Agent],
        socketPath: undefined,
        timeout: undefined,
        method: 'POST',
        path: '/gmail/v1/users/me/watch',
        _ended: true,
        res: [IncomingMessage],
        aborted: undefined,
        timeoutCb: null,
        upgradeOrConnect: false,
        parser: null,
        maxHeadersCount: null,
        _redirectable: [Writable],
        [Symbol(isCorked)]: false,
        [Symbol(outHeadersKey)]: [Object] },
     data: { error: [Object] } },
  code: 500,
  errors:
   [ { domain: 'global',
       reason: 'backendError',
       message: 'Backend Error' } ] }

I'll run it multiple times in a row and sometimes it'll return 200 and sometimes it'll return this 500 error. I'm not hitting my API usage limits. Also it would return a 4xx if I was right?

Any help is much appreciated. Thanks!

e1um avatar Mar 15 '19 16:03 e1um

@e1um, are you running the same requests with different authentication or for different users? If so, it's possible you're running into this bug: https://github.com/googleapis/google-api-nodejs-client/issues/1594.

ghmeier avatar Mar 18 '19 16:03 ghmeier

Same exact authentication for 1 user. I am running it in mocha tests. Not sure if that has something to do with it?

On Mon, Mar 18, 2019 at 12:13 PM Garret Meier [email protected] wrote:

@e1um https://github.com/e1um, are you running the same requests with different authentication or for different users? If so, it's possible you're running into this bug: #1594 https://github.com/googleapis/google-api-nodejs-client/issues/1594.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/googleapis/google-api-nodejs-client/issues/1639#issuecomment-473982673, or mute the thread https://github.com/notifications/unsubscribe-auth/AFejLLQjduA8Z-9nTjLs1x5--NhSkXlzks5vX7sRgaJpZM4b24mf .

-- Eric 845-480-2043 fanum.fm || djelum.com

e1um avatar Mar 19 '19 03:03 e1um

Hi, @e1um You can try the following way. Let me know if it works for you.

const gmail = await google.gmail({ version: 'v1', auth: auth });
        await gmail.users.watch({ userId: 'me',
          requestBody: {
            topicName: `projects/test/topics/test`,
          },
          labelIds: [
            'CATEGORY_UPDATES',
            'DRAFT',
            'CATEGORY_PROMOTIONS',
            'CATEGORY_SOCIAL',
            'CATEGORY_FORUMS',
            'TRASH',
            'CHAT',
            'SPAM',
           ],
          labelFilterAction: 'exclude'
       })
        .then(function(res) {
            console.log(res.data);
        }).catch( function(err) {
            console.log(err);
        })
  };

vishald123 avatar Mar 29 '19 14:03 vishald123

@e1um were you able to try @vishald123's recommendation?

Are you continuing to bump into issues.

bcoe avatar Apr 04 '19 21:04 bcoe