web: add a nicer error page

This commit is contained in:
Alexey Yerin 2021-05-10 20:09:50 +03:00
parent 9674e124cd
commit b67c4398fc
3 changed files with 40 additions and 1 deletions

View File

@ -77,6 +77,14 @@ body {
color: #f8f9fa;
}
a:visited {
color: #9759f6;
}
a {
color: #599bf6;
}
.form__input,
.form__button,
.form__textarea {

30
templates/error.html Normal file
View File

@ -0,0 +1,30 @@
{{define "error"}}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Error</title>
<meta name="description" content="Better interface for Google Translate that is lightweight and doesn't track you">
<link rel="stylesheet" href="/static/style.css" />
</head>
<body>
<h1 class="title">Ooops :(</h1>
<section class="main-section">
<p>Unfortunately, an error occured while processing the translation:<p>
<pre>{{.Error}}</pre>
<p>
You can report this issue to the official mailing list:
<a href="mailto:~yerinalexey/public-inbox@lists.sr.ht">~yerinalexey/public-inbox@lists.sr.ht</a>
<a href="https://lists.sr.ht/~yerinalexey/public-inbox">[archives]</a>.
Please include the text you've submitted and the instance you
were using.
</p>
<a href="/">Go back</a>
</section>
</body>
</html>
{{end}}

3
web.go
View File

@ -31,7 +31,8 @@ func CreateWebHandler(tmpl *template.Template, settings *TranslateSettings) func
translation, err := Translate(settings, from, to, text)
if err != nil {
writeError(w, 500, err)
w.WriteHeader(500)
tmpl.ExecuteTemplate(w, "error", err);
return
}