Implemented on_error callback.