From d83d0b66b04899daec855cbf1057b41db2c8ee04 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 24 Jun 2016 14:01:57 -0400 Subject: [PATCH] Catch exceptions on graph generation --- netbox/extras/api/views.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/netbox/extras/api/views.py b/netbox/extras/api/views.py index 800863922..2436de401 100644 --- a/netbox/extras/api/views.py +++ b/netbox/extras/api/views.py @@ -84,14 +84,19 @@ class TopologyMapView(APIView): # Add all connections to the graph devices = Device.objects.filter(*(device_superset,)) - connections = InterfaceConnection.objects.filter(interface_a__device__in=devices, interface_b__device__in=devices) + connections = InterfaceConnection.objects.filter(interface_a__device__in=devices, + interface_b__device__in=devices) for c in connections: edge = pydot.Edge(c.interface_a.device.name, c.interface_b.device.name) graph.add_edge(edge) # Write the image to disk and return topo_file = tempfile.NamedTemporaryFile() - graph.write(topo_file.name, format='png') + try: + graph.write(topo_file.name, format='png') + except: + return HttpResponse("There was an error generating the requested graph. Ensure that the GraphViz " + "executables have been installed correctly.") response = HttpResponse(FileWrapper(topo_file), content_type='image/png') topo_file.close()