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

Check if response.data is an object or an array before processing. #137

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions src/cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,32 @@ export default class Cursor extends Array<Object> {
};

this._buildObjectsFromResponse = response => {
return response.data.map(item => {
if (typeof response.data === 'object') {
let That: any = this._targetClass;
if (That.name === 'AbstractObject') {
var result = new That();
result.setData(item);
return result;
}
return new That(
item && item.id ? item.id : null,
item,
const result = new That(
response.data && response.id ? response.id : null,
response.data,
undefined,
this._api,
);
});
const returnResponse = [result];
return returnResponse;
} else {
return response.data.map(item => {
let That: any = this._targetClass;
if (That.name === 'AbstractObject') {
var result = new That();
result.setData(item);
return result;
}
return new That(
item && item.id ? item.id : null,
item,
undefined,
this._api,
);
});
}
};
}
}