Add error handling to hooks