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

Fix exception when fetching empty collections #79

Merged
merged 1 commit into from
Sep 12, 2014

Conversation

kadamwhite
Copy link
Collaborator

This crops up especially easily with search queries: no results, no paging; x-wp-totalpages got set to "0", a string, so the previous null check failed to catch the lack of pagination and an exception occurred when parsing the non-existent link header.

Example error:

Possibly unhandled TypeError: Cannot call method 'split' of undefined
    at parse (~/wordpress-rest-api/node_modules/li/lib/index.js:15:33)
    at paginateResponse (~/wordpress-rest-api/lib/shared/wp-request.js:229:14)
    at PostsRequest.returnBody (~/wordpress-rest-api/lib/shared/wp-request.js:131:9)
    [ ... ]

This PR breaks the existing no-paging => pass-through tests into three separate tests to validate different scenarios, and adds additional checks to return before the exception would occur.

This crops up especially easily with search queries: no results, no paging;
x-wp-totalpages got set to "0", a string, so the previous null check failed
to catch the lack of pagination and an exception occurred when parsing the
non-existent link header.
@kadamwhite kadamwhite merged commit 206e175 into master Sep 12, 2014
@kadamwhite kadamwhite deleted the bug/null-exception-on-empty-collections branch September 12, 2014 03:40
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 this pull request may close these issues.

1 participant