I wrap (some) event handlers and callbacks in this function (wrapInErrorHandler(f) returns a function of the same type as f). If they throw an error, the data is posted to a simple json collecting endpoint, which triggers an email action (not too frequently). LoggedError is wrapper for err, to avoid logging the same error multiple times.