Added toJSON function to error object. Closes #276
Merge pull request #277 from arb/error-event

Added toJSON function to error object