Use cleaner error handling in API.

Signed-off-by: Victor Berger <victor.berger@m4x.org>