fix ReferenceError: err is not defined