add error handling to api