From beed83a12beae16f2423d9f164a2857248fc50ae Mon Sep 17 00:00:00 2001
From: George Katsikas <giorgakis.katsikas@gmail.com>
Date: Tue, 21 Jan 2025 14:07:59 +0100
Subject: [PATCH] =?UTF-8?q?fix(graphs):=20=F0=9F=A5=85=20catch=20download?=
 =?UTF-8?q?=20of=20empty=20figure?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 scipost_django/graphs/views.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/scipost_django/graphs/views.py b/scipost_django/graphs/views.py
index d69a3036e..090e243d0 100644
--- a/scipost_django/graphs/views.py
+++ b/scipost_django/graphs/views.py
@@ -4,6 +4,7 @@ __license__ = "AGPL v3"
 
 import io
 from django.contrib.auth.decorators import login_required, permission_required
+from django.http import Http404
 from django.shortcuts import HttpResponse, render
 from django.template.response import TemplateResponse
 from django.utils.decorators import method_decorator
@@ -77,6 +78,9 @@ class PlotView(View):
         figure = self.render_figure()
         bytes_io = io.BytesIO()
 
+        if figure is None:
+            raise Http404("No figure exists with the given options")
+
         match file_type:
             case "svg":
                 figure.savefig(bytes_io, format="svg")
-- 
GitLab