Verbessere Logging und Fehlerbehandlung
This commit is contained in:
parent
c737818ce4
commit
6e97d867de
14 changed files with 223 additions and 88 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
|
@ -10,16 +11,24 @@ func (b *BaseHandler) ConfirmRequestHandler(w http.ResponseWriter, req *http.Req
|
|||
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
Templates.ExecuteTemplate(w, "requestNotFound.html", struct{}{})
|
||||
templateError := Templates.ExecuteTemplate(w, "requestNotFound.html", struct{}{})
|
||||
if templateError != nil {
|
||||
log.Printf("Error executing template requestNotFound.html: %s", templateError.Error())
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
err = b.requestRepo.Execute(request)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
Templates.ExecuteTemplate(w, "executeFailure.html", err.Error())
|
||||
templateError := Templates.ExecuteTemplate(w, "executeFailure.html", err.Error())
|
||||
if templateError != nil {
|
||||
log.Printf("Error executing template executeFailure.html: %s", templateError.Error())
|
||||
}
|
||||
return
|
||||
}
|
||||
Templates.ExecuteTemplate(w, "executeSuccess.html", struct{}{})
|
||||
|
||||
templateError := Templates.ExecuteTemplate(w, "executeSuccess.html", struct{}{})
|
||||
if templateError != nil {
|
||||
log.Printf("Error executing template executeSuccess.html: %s", templateError.Error())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"officeHours/models"
|
||||
"strconv"
|
||||
|
@ -18,7 +19,10 @@ func (b *BaseHandler) DeleteOfficeHourHandler(w http.ResponseWriter, req *http.R
|
|||
w.WriteHeader(http.StatusBadRequest)
|
||||
}
|
||||
_, err = b.requestRepo.Add(officeHour, models.RequestDelete)
|
||||
Templates.ExecuteTemplate(w, "deleteSuccess.html", struct{}{})
|
||||
templateError := Templates.ExecuteTemplate(w, "deleteSuccess.html", struct{}{})
|
||||
if templateError != nil {
|
||||
log.Printf("Error executing template deleteSuccess.html: %s", templateError.Error())
|
||||
}
|
||||
} else {
|
||||
officeHours, _ := b.officeHourRepo.GetAll(true)
|
||||
timetable, slots := b.GetTimetable(officeHours)
|
||||
|
|
|
@ -3,6 +3,7 @@ package controllers
|
|||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"officeHours/models"
|
||||
"strconv"
|
||||
|
@ -19,7 +20,10 @@ func (b *BaseHandler) GetByRoomHandler(w http.ResponseWriter, req *http.Request)
|
|||
b.RootHandler(w, req)
|
||||
return
|
||||
}
|
||||
officeHours, _ := b.officeHourRepo.FindByRoom(room, true)
|
||||
officeHours, err := b.officeHourRepo.FindByRoom(room, true)
|
||||
if err != nil {
|
||||
log.Printf("Error getting office hours for room %s: %s", room.Name, err.Error())
|
||||
}
|
||||
timetable, slots := b.GetTimetable(officeHours)
|
||||
b.writeTimetablePage(w, req, b.printTimetable(timetable, slots, false))
|
||||
}
|
||||
|
@ -34,7 +38,10 @@ func (b *BaseHandler) GetByCourseHandler(w http.ResponseWriter, req *http.Reques
|
|||
b.RootHandler(w, req)
|
||||
return
|
||||
}
|
||||
officeHours, _ := b.officeHourRepo.FindByCourse(course, true)
|
||||
officeHours, err := b.officeHourRepo.FindByCourse(course, true)
|
||||
if err != nil {
|
||||
log.Printf("Error getting office hours for course %s: %s", course.Name, err.Error())
|
||||
}
|
||||
timetable, slots := b.GetTimetable(officeHours)
|
||||
b.writeTimetablePage(w, req, b.printTimetable(timetable, slots, false))
|
||||
}
|
||||
|
@ -51,9 +58,10 @@ func (b *BaseHandler) writeTimetablePage(w http.ResponseWriter, req *http.Reques
|
|||
SelectedRoom int
|
||||
SelectedCourse int
|
||||
}{courses, rooms, timetable, selectedRoom, selectedCourse}
|
||||
err := Templates.ExecuteTemplate(w, "index.html", data)
|
||||
if err != nil {
|
||||
w.Write([]byte(fmt.Sprintf("Template konnte nicht geparst werden : %s", err.Error())))
|
||||
templateError := Templates.ExecuteTemplate(w, "index.html", data)
|
||||
if templateError != nil {
|
||||
log.Printf("Error executing template index.html: %s", templateError.Error())
|
||||
w.Write([]byte(fmt.Sprintf("Template konnte nicht geparst werden : %s", templateError.Error())))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"officeHours/models"
|
||||
)
|
||||
|
||||
var Templates, _ = template.Must(template.ParseFiles(
|
||||
var Templates, TemplateError = template.Must(template.ParseFiles(
|
||||
"templates/addFailure.html",
|
||||
"templates/addMask.html",
|
||||
"templates/addSuccess.html",
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"bytes"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"officeHours/models"
|
||||
)
|
||||
|
||||
|
@ -84,7 +85,10 @@ func (b *BaseHandler) printTimetable(timetable map[models.Date]map[int]models.Of
|
|||
MinuteGranularity int
|
||||
DeleteIcons bool
|
||||
}{OfficeHour: current, MinuteGranularity: b.config.Date.MinuteGranularity, DeleteIcons: deleteIcons}
|
||||
Templates.ExecuteTemplate(&celldata, "td.html", data)
|
||||
templateError := Templates.ExecuteTemplate(&celldata, "td.html", data)
|
||||
if templateError != nil {
|
||||
log.Printf("Error executing template td.html: %s", templateError.Error())
|
||||
}
|
||||
tableBody += celldata.String()
|
||||
}
|
||||
} else {
|
||||
|
@ -116,6 +120,9 @@ func (b *BaseHandler) printTimetable(timetable map[models.Date]map[int]models.Of
|
|||
slots[4],
|
||||
template.HTML(tableBody),
|
||||
}
|
||||
Templates.ExecuteTemplate(&table, "officeHourTable.html", tableData)
|
||||
templateError := Templates.ExecuteTemplate(&table, "officeHourTable.html", tableData)
|
||||
if templateError != nil {
|
||||
log.Printf("Error executing template officeHourTable.html: %s", templateError.Error())
|
||||
}
|
||||
return template.HTML(table.String())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue