make the errorHandler be a factory that takes a callback as an argument

Note that the actual changes are much smaller than what it looks like in the diff.  You should diff using something that ignores whitespace.