Modify on_error callback to include the reason.

- Old version - on_error/0 - you could only signal a generic error
- New version - on_error/1 - takes as argument the error reason
    The error reason may be of different type depending on
    connection status - on connection upgrade (http connection
    problems) or on tcp transmission/retransmissions