From 7ae363f6d1bd4da7fb2751d7c352aedbb75f4456 Mon Sep 17 00:00:00 2001 From: MinRK Date: Tue, 7 Jan 2014 15:15:57 -0800 Subject: [PATCH] turn missing dependencies in nbconvert to 500 errors pygments is the only such example at this time --- IPython/html/nbconvert/handlers.py | 5 ++++- IPython/html/services/nbconvert/handlers.py | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/IPython/html/nbconvert/handlers.py b/IPython/html/nbconvert/handlers.py index dc4d2e48c..2fb6f4586 100644 --- a/IPython/html/nbconvert/handlers.py +++ b/IPython/html/nbconvert/handlers.py @@ -61,7 +61,10 @@ def get_exporter(format, **kwargs): # should this be 400? raise web.HTTPError(404, u"No exporter for format: %s" % format) - return Exporter(**kwargs) + try: + return Exporter(**kwargs) + except Exception as e: + raise web.HTTPError(500, "Could not construct Exporter: %s" % e) class NbconvertFileHandler(IPythonHandler): diff --git a/IPython/html/services/nbconvert/handlers.py b/IPython/html/services/nbconvert/handlers.py index fb79aa54d..1c74de5d6 100644 --- a/IPython/html/services/nbconvert/handlers.py +++ b/IPython/html/services/nbconvert/handlers.py @@ -3,10 +3,6 @@ import json from tornado import web from ...base.handlers import IPythonHandler, json_errors -try: - from IPython.nbconvert.exporters.export import exporter_map -except ImportError: - exporter_map = {} class NbconvertRootHandler(IPythonHandler): SUPPORTED_METHODS = ('GET',) @@ -14,6 +10,10 @@ class NbconvertRootHandler(IPythonHandler): @web.authenticated @json_errors def get(self): + try: + from IPython.nbconvert.exporters.export import exporter_map + except ImportError as e: + raise web.HTTPError(500, "Could not import nbconvert: %s" % e) res = {} for format, exporter in exporter_map.items(): res[format] = info = {}