Fix bugs in error handler.
Fix bugs in error handler.

materialsproject/custodian,specter119/custodian,materialsproject/custodian,alberthxf/custodian,materialsproject/custodian,davidwaroquiers/custodian,specter119/custodian,xhqu1981/custodian,specter119/custodian