Backend error handling

Adding basic error handling to the backend.js file. I hope I'm doing that correctly as I haven't done it before.