refactored for maintainability
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"git.haelnorr.com/h/golib/hws"
|
||||
"git.haelnorr.com/h/oslstats/internal/notify"
|
||||
"git.haelnorr.com/h/oslstats/internal/view/page"
|
||||
)
|
||||
|
||||
@@ -16,12 +17,6 @@ func NotifyTester(s *hws.Server) http.Handler {
|
||||
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()
|
||||
@@ -30,19 +25,15 @@ func NotifyTester(s *hws.Server) http.Handler {
|
||||
level := r.Form.Get("type")
|
||||
message := r.Form.Get("message")
|
||||
|
||||
var err error
|
||||
switch level {
|
||||
case "success":
|
||||
err = notifySuccess(s, r, title, message, nil)
|
||||
notify.Success(s, w, r, title, message, nil)
|
||||
case "info":
|
||||
err = notifyInfo(s, r, title, message, nil)
|
||||
notify.Info(s, w, r, title, message, nil)
|
||||
case "warn":
|
||||
err = notifyWarn(s, r, title, message, nil)
|
||||
notify.Warn(s, w, r, title, message, nil)
|
||||
case "error":
|
||||
err = notifyInternalServiceError(s, r, message, testErr)
|
||||
}
|
||||
if err != nil {
|
||||
throwInternalServiceError(s, w, r, "Error notifying client", err)
|
||||
notify.InternalServiceError(s, w, r, message, testErr)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user