Update sample.js

include better error handling from #1