Better error handling in sync handler