added custom error handler

Would be nice to have some UT for this method.