IoT devices are decentralized and deployed in unstable environments, which causes them to be prone to various types of faults, such as power failure and network disruption. Yet, current IoT platforms require programmers to handle faults manually, a complex and error-prone task. In this paper, we present IoTRepair, a fault-handling system for IoT that (1) integrates with fault identification modules to track faulty devices, (2) provides a library of fault-handling functions for effectively handling different fault types, (3) provides a fault handler on top of the library for autonomous IoT fault handling, with deployed devices, user preferences, and developer configuration as input. Through an evaluation in a simulated lab environment, we find IoTRepair reduces the incorrect states on average 63.51%, which corresponds to less unsafe and insecure device states. Overall, through a systematic design of an IoT fault handler, we provide users flexibility and convenience in handling complex IoT fault handling, allowing safer IoT environments.