handle errors in template