Add better exception handling to backend endpoints