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

TypeError: initialResult[field] is not iterable - when only 1 item is returned from site. #28

Open
VirtueMe opened this issue Mar 3, 2020 · 0 comments

Comments

@VirtueMe
Copy link

VirtueMe commented Mar 3, 2020

How to reproduce.

oai-pmh list-sets https://oai.mikromarc.no/OAI/mic 

The reason is that the result will not be an array because of the option to parseString explicitArray: false,. This results in that you can't iterate on it.

There is two ways to solve this in oai-pmh-list.js

Concat returned item into an array in both locations.

// Line 33
for (const item of [].concat(initialResult[field])) {
// Line 49
for (const item of [].concat(result[field])) {

A alternative is to check if the returned object if it is iterable.

if (typeof initialResult[field][Symbol.iterator] === 'function') {
  for (const item of initialResult[field]) {
    yield item
  }
}
else {
  yield  initialResult[field]
}
if (typeof result[field][Symbol.iterator] === 'function') {
  for (const item of result[field]) {
    yield item
  }
}
else {
  yield  result[field]
}
VirtueMe added a commit to VirtueMe/oai-pmh that referenced this issue Mar 4, 2020
VirtueMe added a commit to VirtueMe/oai-pmh that referenced this issue Mar 4, 2020
VirtueMe added a commit to VirtueMe/oai-pmh that referenced this issue Mar 4, 2020
VirtueMe added a commit to VirtueMe/oai-pmh that referenced this issue Apr 11, 2020
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

1 participant