web, api: terminate request on parse error

When a parser error occurs, the request is not terminated which causes
the HTML page to be dumped after the error message.
This commit is contained in:
Alexey Yerin 2021-03-15 19:42:17 +03:00
parent 1526372946
commit 3f6bdee18d
2 changed files with 2 additions and 0 deletions

1
api.go
View File

@ -25,6 +25,7 @@ func CreateApiHandler(settings *TranslateSettings) func(w http.ResponseWriter, r
translation, err := Translate(settings, from, to, text)
if err != nil {
writeError(w, 500, err)
return
}
w.Write([]byte(translation))

1
web.go
View File

@ -27,6 +27,7 @@ func CreateWebHandler(tmpl *template.Template, settings *TranslateSettings) func
translation, err := Translate(settings, from, to, text)
if err != nil {
writeError(w, 500, err)
return
}
tmpl.ExecuteTemplate(w, "index", indexPageData{Languages, from, to, text, translation})