better error handling
return url & end stream
modified sample.js
modified sample.js