Add error handling to backend