Right. Which is fine. You just have to know what individual (internal) function will do in the extension to know if it will return 0 as success or failure, or try to unify it by "converting" the return value to either convention.

In any case. This code snippet is correct. It will return FAILURE (-1) on failure, and the count (0 or more) on success. If the count is 0 (e.g., not documents added) it will shortcircut and not send anything to the server.