node: check if `er` is undefined

Throwing `undefined` causes segmentation fault when uncaught.