From 0a2d3d4ea773e69d78a2bd9840054bef0cd90b8e Mon Sep 17 00:00:00 2001
From: George Katsikas <giorgakis.katsikas@gmail.com>
Date: Tue, 21 Jan 2025 10:48:49 +0100
Subject: [PATCH] =?UTF-8?q?feat(graphs):=20=F0=9F=A5=85=20generalize=20plo?=
 =?UTF-8?q?t=20exception=20handling?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 scipost_django/graphs/graphs/plotkind.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/scipost_django/graphs/graphs/plotkind.py b/scipost_django/graphs/graphs/plotkind.py
index 270db58ec..3646795aa 100644
--- a/scipost_django/graphs/graphs/plotkind.py
+++ b/scipost_django/graphs/graphs/plotkind.py
@@ -4,6 +4,7 @@ __license__ = "AGPL v3"
 from django import forms
 from django.db.models import Q, Avg, Count, Sum
 from matplotlib.figure import Figure
+from matplotlib.axes import Axes
 import pandas as pd
 
 from .options import BaseOptions
@@ -73,13 +74,13 @@ class PlotKind:
         try:
             x, y = self.get_data()
             ax.plot(x, y)
-        except ValueError as e:
-            self.display_plotting_error(ax)
+        except Exception as e:
+            self.display_plotting_error(ax, e)
 
         return fig
 
-    def display_plotting_error(self, ax):
-        ax.text(0.5, 0.5, f"No data to plot", ha="center", va="center")
+    def display_plotting_error(self, ax: Axes, error: Exception):
+        ax.text(0.5, 0.5, str(error), ha="center", va="center")
         ax.grid(False)
         ax.axis("off")
 
-- 
GitLab