fixed relationship issues
This commit is contained in:
50
internal/handlers/notifytest.go
Normal file
50
internal/handlers/notifytest.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"git.haelnorr.com/h/golib/hws"
|
||||
"git.haelnorr.com/h/oslstats/internal/view/page"
|
||||
)
|
||||
|
||||
// NotifyTester handles responses to the / path. Also serves a 404 Page for paths that
|
||||
// don't have explicit handlers
|
||||
func NotifyTester(s *hws.Server) http.Handler {
|
||||
return http.HandlerFunc(
|
||||
func(w http.ResponseWriter, r *http.Request) {
|
||||
testErr := errors.New("This is a stack trace. No really i swear. Just pretend ok? Thanks")
|
||||
if r.Method == "GET" {
|
||||
// page, _ := ErrorPage(hws.HWSError{
|
||||
// StatusCode: http.StatusTeapot,
|
||||
// Message: "This error has been rendered as a test",
|
||||
// Error: testErr,
|
||||
// })
|
||||
// page.Render(r.Context(), w)
|
||||
renderSafely(page.Test(), s, r, w)
|
||||
} else {
|
||||
_ = r.ParseForm()
|
||||
// target := r.Form.Get("target")
|
||||
title := r.Form.Get("title")
|
||||
level := r.Form.Get("type")
|
||||
message := r.Form.Get("message")
|
||||
|
||||
var err error
|
||||
switch level {
|
||||
case "success":
|
||||
err = notifySuccess(s, r, title, message, nil)
|
||||
case "info":
|
||||
err = notifyInfo(s, r, title, message, nil)
|
||||
case "warn":
|
||||
err = notifyWarn(s, r, title, message, nil)
|
||||
case "error":
|
||||
err = notifyInternalServiceError(s, r, message, testErr)
|
||||
}
|
||||
if err != nil {
|
||||
throwInternalServiceError(s, w, r, "Error notifying client", err)
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user