Update example

Update examples to display good practices and add event handlers for all the possible `error` events.