reimplement API error handling