Improve heatmap error handling in the backend