Fix for item.save() never calling its callback function #86
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I didn't see any contributor guidelines, but trying this anyway because the issue is a showstopper for us (since the uncaught error crashes Node).
Fixes #74.
Problem
When item.save(callbackFn) is called with invalid input, the server rejects the request with a 400 response, as expected. The client, however, does not call the given callbackFn to provide the error to the caller. Instead, an uncaught error is thrown trying to wrap the
nulldata into a collection.Not only does this behavior violate the specified contract by not calling the callback function, but the uncaught error can crash Node completely, with no way for an outsider to
try/catchthe save() call itself, since the error happens in its own callback.This fix adds unit tests demonstrating the problem, and fixes the problem by only wrapping non-
nullresponsedata.To Reproduce
In issue #74 several people have described scenarios that led to this problem. One summary from @JohannesHome in the issue:
More specific repro scenarios include trying to save() a Person who has already been deleted (@super-cache-money) and setting an invalid field ID before save() (@vasiabikeru).
Summary
Please consider merging this into the API client to fix what appears to be a very major problem.