Add onerror handler
Merge pull request #6 from samgiles/error_handling

Add onerror handler