1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-09-04 10:06:24 -07:00

remove more gclog calls from gcsql

This commit is contained in:
Eggbertx 2022-09-03 15:25:50 -07:00
parent ffcf4a1e61
commit 17833e78ad
3 changed files with 12 additions and 25 deletions

View file

@ -2,11 +2,12 @@ package gcsql
import (
"database/sql"
"errors"
"fmt"
"html/template"
"net/http"
"time"
"github.com/gochan-org/gochan/pkg/gclog"
"github.com/gochan-org/gochan/pkg/gcutil"
)
@ -59,17 +60,12 @@ func EndStaffSession(writer http.ResponseWriter, request *http.Request) error {
if err = QueryRowSQL(`SELECT staff_id FROM DBPREFIXsessions WHERE data = ?`,
[]interface{}{session.Value}, []interface{}{&staffID}); err != nil && err != sql.ErrNoRows {
// something went wrong with the query and it's not caused by no rows being returned
gclog.Printf(gclog.LStaffLog|gclog.LErrorLog,
"Failed getting staff ID for deletion with cookie data %q", sessionVal)
return err
return errors.New("failed getting staff ID: " + err.Error())
}
_, err = ExecSQL(`DELETE FROM DBPREFIXsessions WHERE data = ?`, sessionVal)
if err != nil && err != sql.ErrNoRows {
gclog.Println(gclog.LStaffLog|gclog.LErrorLog,
// something went wrong when trying to delete the rows and it's not caused by no rows being returned
"Failed deleting session for staff with id", staffID)
return err
return fmt.Errorf("failed clearing session for staff with id %d", staffID)
}
return nil
}

View file

@ -81,7 +81,9 @@ var actions = []Action{
Title: "Logout",
Permissions: JanitorPerms,
Callback: func(writer http.ResponseWriter, request *http.Request, wantsJSON bool) (output interface{}, err error) {
gcsql.EndStaffSession(writer, request)
if err = gcsql.EndStaffSession(writer, request); err != nil {
return "", err
}
http.Redirect(writer, request,
config.GetSystemCriticalConfig().WebRoot+"manage",
http.StatusSeeOther)

View file

@ -23,19 +23,11 @@ func (esa *ErrStaffAction) Error() string {
}
func serveError(writer http.ResponseWriter, field string, action string, message string, isJSON bool) {
if isJSON {
writer.Header().Add("Content-Type", "application/json")
writer.Header().Add("Cache-Control", "max-age=5, must-revalidate")
errJSON, _ := gcutil.MarshalJSON(ErrStaffAction{
ErrorField: field,
Action: action,
Message: message,
}, true)
serverutil.MinifyWriter(writer, []byte(errJSON), "application/json")
return
}
serverutil.ServeErrorPage(writer, message)
serverutil.ServeError(writer, message, isJSON, map[string]interface{}{
"error": field,
"action": action,
"message": message,
})
}
func isRequestingJSON(request *http.Request) bool {
@ -98,10 +90,7 @@ func CallManageFunction(writer http.ResponseWriter, request *http.Request) {
output, err = action.Callback(writer, request, wantsJSON)
}
if err != nil {
staffName, _ := getCurrentStaff(request)
// writer.WriteHeader(500)
gclog.Printf(gclog.LStaffLog|gclog.LErrorLog,
"Error accessing manage page %s by %s: %s", actionID, staffName, err.Error())
serveError(writer, "actionerror", actionID, err.Error(), wantsJSON || (action.JSONoutput == AlwaysJSON))
return
}