fix 'ReferenceError: error is not defined'

There is no variable 'error' defined, so the error case fails. I changed it to throw a new generic Error which fixes the problem.