fixed typo

var error object was being created in a few places but the function was returning err instead of error.