Add API error handling.
Merge branch 'api' into api-exception
Merge branch 'api' into api-exception