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

Listener exception generates status 400, error should contain contextual error information #318

Open
semireg opened this issue May 9, 2023 · 3 comments

Comments

@semireg
Copy link

semireg commented May 9, 2023

Hi,

It took me a few days to track down the source of a strange subscription bug.

In my case, I had a listener with a presence function such as:

  presence: (presenceEvent) => {
    const { uuid, action } = presenceEvent;
    const someVar = null.replace('foo', 'bar'); // Throws

Upon connection and subscription withPresence, this generates a status listener event with code 400 and empty errorData:

statusEvent:{
   "statusCode": 400,
   "error": true,
   "operation": "PNSubscribeOperation",
   "errorData": {},
   "category": "PNUnknownCategory"
}

I went in and added debug to show me the e.stack on line 237 of core/components/endpoint.js:

    responseP
      .then((result) => {
        if (callback) {
          callback(status, result);
        } else if (promiseComponent) {
          promiseComponent.fulfill(result);
        }
      })
      .catch((e) => {
        console.log(`onResponse caught error at ${JSON.stringify(e.stack, null, 3)}`);  // DEBUG HERE
        
        if (callback) {
          let errorData = e;

          if (endpoint.getOperation() === operationConstants.PNSubscribeOperation) {
            errorData = {
              statusCode: 400,
              error: true,
              operation: endpoint.getOperation(),
              errorData: e,
              category: categoryConstants.PNUnknownCategory,
            };
          }

          callback(errorData, null);
        } else if (promiseComponent) {
          promiseComponent.reject(new PubNubError('PubNub call failed, check status for details', e));
        }
      });

The response was pretty obvious:

onResponse caught error at "TypeError: Cannot read properties of undefined (reading 'replace')\n    at Object.presence ..... pubnub-javascript/lib/core/components/endpoint.js:235:17\n    at processTicksAndRejections (node:internal/process/task_queues:96:5)"

It would have saved me a lot of time if the errorData contained at least some information.

@semireg semireg changed the title Listener exceptions generate status 400, error should contain contextual error information Listener exception generates status 400, error should contain contextual error information May 9, 2023
@alikazi88
Copy link

I assume this is a server-side problem as there is nothing wrong with the code you mentioned I did not get a chance to go through the SDK docs to Consult the documentation or API reference provided by the server to understand the expected request format and any specific requirements for subscribing with presence. apart from that the SDK needs to be updated

@bhupendra-cvent
Copy link

we are also experiencing a lot of errors related to PNUnknownCategory while subscribing to the listener.

@semireg
Copy link
Author

semireg commented Jun 9, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants