Verbessere Logging und Fehlerbehandlung

This commit is contained in:
Gonne 2022-09-21 22:24:08 +02:00
parent c737818ce4
commit 6e97d867de
14 changed files with 223 additions and 88 deletions

View file

@ -149,12 +149,24 @@ func (b *BaseHandler) AddOfficeHourHandler(w http.ResponseWriter, req *http.Requ
id, err := b.officeHourRepo.Add(officeHour)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
Templates.ExecuteTemplate(w, "addFailure.html", err)
templateError := Templates.ExecuteTemplate(w, "addFailure.html", err)
if templateError != nil {
log.Printf("Error executing template addFailure.html: %s", templateError.Error())
}
return
}
officeHour, _ = b.officeHourRepo.FindById(id)
b.requestRepo.Add(officeHour, models.RequestActivate)
Templates.ExecuteTemplate(w, "addSuccess.html", struct{}{})
officeHour, err = b.officeHourRepo.FindById(id)
if err != nil {
log.Printf("Error finding new office hour by id %d: %s", id, err.Error())
}
_, err = b.requestRepo.Add(officeHour, models.RequestActivate)
if err != nil {
log.Printf("Error adding request: %s", err.Error())
}
templateError := Templates.ExecuteTemplate(w, "addSuccess.html", struct{}{})
if templateError != nil {
log.Printf("Error executing template addSuccess.html: %s", templateError.Error())
}
}
}
@ -165,10 +177,10 @@ func (b *BaseHandler) writeAddOfficeHourMask(w http.ResponseWriter, req *http.Re
if len(data.Errors) != 0 {
w.WriteHeader(http.StatusBadRequest)
}
err := Templates.ExecuteTemplate(w, "addMask.html", data)
if err != nil {
log.Printf("Template addMask.html could not be parsed: %s", err.Error())
w.Write([]byte(fmt.Sprintf("Template konnte nicht geparst werden : %s", err.Error())))
templateError := Templates.ExecuteTemplate(w, "addMask.html", data)
if templateError != nil {
log.Printf("Error executing template addMask.html: %s", templateError.Error())
w.Write([]byte(fmt.Sprintf("Template konnte nicht geparst werden : %s", templateError.Error())))
return
}
}