~artemis/paste

a91256ffab624fbec354e270643275b483f147b1 — Diane 3 months ago fe6758c
Uniformized error pages
4 files changed, 15 insertions(+), 23 deletions(-)

M handlers.go
M static/style.css
M templates/http-error.html
M todo.txt
M handlers.go => handlers.go +6 -1
@@ 65,7 65,7 @@ type GenericError struct {

var genericErrors = map[int]GenericError{
	http.StatusBadRequest:          {"Bad request", "You sent a request the server cannot handle."},
	http.StatusNotFound:            {"Page not found", "This document could not be found. Maybe it expired?"},
	http.StatusNotFound:            {"Page not found", "No page could be found at the given URL"},
	http.StatusInternalServerError: {"Internal server error", "The server crashed during the request."},
}



@@ 84,6 84,7 @@ func (h Handlers) GetRouter() *mux.Router {

	r := mux.NewRouter()
	r.Use(LogRequest)
	r.NotFoundHandler = http.HandlerFunc(h.handle404)

	r.HandleFunc("/", h.handleNewPaste).
		Methods(http.MethodPost)


@@ 134,6 135,10 @@ func (h Handlers) handleAbout(w http.ResponseWriter, req *http.Request) {
	ErrIf(h.Templates.ExecuteTemplate(w, "about", nil))
}

func (h Handlers) handle404(w http.ResponseWriter, req *http.Request) {
	h.GenericHTTPError(404, nil)(w, req)
}

// endregion

// region Form validators

M static/style.css => static/style.css +4 -0
@@ 62,6 62,10 @@ nav a {
	color: var(--foreground);
}

.error {
	text-align: center;
}

.spaced {
	display: flex;
	justify-content: space-between;

M templates/http-error.html => templates/http-error.html +4 -21
@@ 2,31 2,14 @@
	<!DOCTYPE html>
	<html lang="en">
	<head>
		{{template "header"}}
		<style>
			main.error {
				margin-top: 10em;
				text-align: center;
				font-family: monospace, monospace;
			}

			h1::before {
				content: '';
			}

			@media screen and (min-width: 700px) {
				main.error {
					width: 700px;
					margin: 10em auto auto auto;
				}
			}
		</style>
		{{template "head"}}
		<title>{{.Error.Title}}</title>
	</head>
	<body>
	<main class="error">
		<h1 class="text-3xl">{{.Error.Title}}</h1>
		<h1>{{.Error.Title}}</h1>
		<p>{{.Error.Description}}</p>
		<a href="/" class="underline font-medium text-blue-500">Back to home page</a>
		<a href="/">Back to home page</a>
	</main>
	</body>
	</html>

M todo.txt => todo.txt +1 -1
@@ 1,5 1,5 @@
x 2020-06-21 text trimming on paste
uniformized error pages
x 2020-06-21 uniformized error pages
server-side syntaxic coloration
x 2020-06-21 mode changer
x 2020-06-21 change routing system to use GET parameters and - as prefix