Check if there is such extension before getting it: 
if (error.hasExtension(...)) {
  error.getExtension(...);
}