Skip to content

[JavaScript] Handling empty array #4653

@khorolets

Description

@khorolets

Hi! Thank for your great work once again! I wonder if you can help me.

Description

I'm using generated javascript client in my project and I've met a bug, I suppose.

If my API returns an empty array client is returning it to me as a string and fails with message:

TypeError: data.map is not a function

It occurs in src/ApiClient.js:exports.convertToType()

} else if (Array.isArray(type)) {
          // for array type like: ['String']
          var itemType = type[0];

          return data.map(function(item) {
            return exports.convertToType(item, itemType);
          });
        } else if (typeof type === 'object') {

I suppose this data is handled somewhere in exports.prototype.deserialize

Because of

if (data == null || !Object.keys(data).length) {
      // SuperAgent does not always produce a body; use the unparsed response as a fallback
      data = response.text;
    }

Can you help me?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions