aboutsummaryrefslogtreecommitdiff
path: root/error.go
blob: 114bbf19ecbc6b494bf9c6c6a5cde3e687a44ccf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package main

import (
	"net/http"
)

type NotAuthorized struct{}

func (n NotAuthorized) WithError(err error) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("WWW-Authenticate", `Basic realm="Pour accéder à Bagage, veuillez entrer vos identifiants Deuxfleurs"`)
		w.WriteHeader(401)
		w.Write([]byte("401 Unauthorized\n"))
	})
}

type InternalError struct{}

func (i InternalError) WithError(err error) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(500)
		w.Write([]byte("500 Internal Server Error\n"))
	})
}