API error handling. closes #34