Better handling of error for API