make sure onerror callback is being executed when an error occurs