improved error handling in api and frontend routes