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

Prevent Circular Structure error for slack service #5

Closed
eason9487 opened this issue May 5, 2017 · 0 comments · Fixed by #6
Closed

Prevent Circular Structure error for slack service #5

eason9487 opened this issue May 5, 2017 · 0 comments · Fixed by #6

Comments

@eason9487
Copy link

Slack will use JSON.stringify(value) to handle non-string value,
so it would throw Circular Structure error when value having circular reference.
https://github.com/slackapi/node-slack-sdk/blob/fb4bc6fe62e055581d342b8279350d59325930d3/lib/clients/helpers.js#L30

It throws exception when passing request object from router of Express

value: logMessageFields[key],

We can avoid it by passing value to a filter function likes:

import { forEach, isObject } from 'lodash';

function removeCircularStructure(object, set = new Set(), nextObject = {}) {
  forEach(object, (value, key) => {
    if (isObject(value)) {
      if (set.has(value)) {
        return;
      }

      set.add(value);
      nextObject[key] = removeCircularStructure(value, set);
      return;
    }

    nextObject[key] = value;
  });

  return nextObject;
}

Or do something else to prevent this error.

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

Successfully merging a pull request may close this issue.

1 participant