~yerinalexey/gtranslate

b67c4398fcbf66760c38d3f83e180a1c4f1fe426 — Alexey Yerin 4 months ago 9674e12
web: add a nicer error page
3 files changed, 40 insertions(+), 1 deletions(-)

M static/style.css
A templates/error.html
M web.go
M static/style.css => static/style.css +8 -0
@@ 77,6 77,14 @@ body {
    color: #f8f9fa;
  }

  a:visited {
    color: #9759f6;
  }

  a {
    color: #599bf6;
  }

  .form__input,
  .form__button,
  .form__textarea {

A templates/error.html => templates/error.html +30 -0
@@ 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}}

M web.go => web.go +2 -1
@@ 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
		}