Skip to content

makeString API returns "undefined" for undefined which is logged to Intercom #1

@dvbsknd

Description

@dvbsknd

As can be seen in this request body, when variables have an undefined value this is cast to a String as the literal word "undefined" by the makeString API.

Image

It would be good to have a check to ensure that undefined remains undefined and is not cast to a String, e.g.:

function parseType (type, value) {
  switch (type) {
    case 'text':
      // Modified line to prevent 'undefined' being
      // sent as a String to Intercom:
      return value ? makeString(value) : undefined;
    case 'number':
      return makeNumber(value);
    case 'boolean':
    case 'bool':
      const lowerCaseValue = value.toLowerCase();
      return lowerCaseValue === "true" || lowerCaseValue === "yes" || lowerCaseValue === "1";
  }

  return value;
}

Happy to provide a PR if you like.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions