Fix bugs in error handler.