From 20fd1e7a44d67e091b6c0c67f7c98cb95c6bf538 Mon Sep 17 00:00:00 2001 From: Eliot Whalan Date: Thu, 23 Jun 2016 09:55:08 +1000 Subject: [PATCH] Add pygments error handling --- main.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index c7fb05a..cfeb168 100644 --- a/main.go +++ b/main.go @@ -185,7 +185,11 @@ func langHandler(w http.ResponseWriter, r *http.Request) { paste := vars["pasteId"] lang := vars["lang"] s := getPaste(paste) - highlight := pygments.Highlight(html.UnescapeString(s), html.EscapeString(lang), "html", "full, style=autumn,linenos=True, lineanchors=True,anchorlinenos=True,", "utf-8") + highlight, err := pygments.Highlight(html.UnescapeString(s), html.EscapeString(lang), "html", "full, style=autumn,linenos=True, lineanchors=True,anchorlinenos=True,", "utf-8") + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } io.WriteString(w, highlight) }