Fixed really dodgy error handling in API.