diff options
author | Quentin <quentin@deuxfleurs.fr> | 2021-08-23 20:40:03 +0200 |
---|---|---|
committer | Quentin <quentin@deuxfleurs.fr> | 2021-08-23 20:40:03 +0200 |
commit | 15e4d10fd4b35a2e70cc4fa6ad4117cd5c402cbc (patch) | |
tree | 0fe31ac79d5dbe480b1b386845b3dd8fcaa55bd4 /error.go | |
parent | 5d64be33e64eb75160b6fe37b01997de7e96237a (diff) | |
download | bagage-15e4d10fd4b35a2e70cc4fa6ad4117cd5c402cbc.tar.gz bagage-15e4d10fd4b35a2e70cc4fa6ad4117cd5c402cbc.zip |
Refactor the codebase
Diffstat (limited to 'error.go')
-rw-r--r-- | error.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/error.go b/error.go new file mode 100644 index 0000000..114bbf1 --- /dev/null +++ b/error.go @@ -0,0 +1,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")) + }) +} |