Improve error handling in api files

Change-Id: Ib9dccf5641d72aa5d16ad3179d0df030c7664fa6
Closes-Bug: #1364018
Merge "Improve error handling in api files"