Fix error reporting in api calls.
Merge remote-tracking branch 'upstream/master'