Adding error handling to backend.js file.