[API] Fix some error handling

Change-Id: Id59b0e133ad96bf0ee38e61f1b316555a44337ac