package errorhandlers import ( "encoding/json" "fmt" "net/http" "os" "gitea.futuresens.co.uk/futuresens/cmstypes" "gitea.futuresens.co.uk/futuresens/hardlink/internal/mail" log "github.com/sirupsen/logrus" ) // writeError is a helper to send a JSON error and HTTP status in one go. func WriteError(w http.ResponseWriter, status int, msg string) { theResponse := cmstypes.StatusRec{ Code: status, Message: msg, } w.Header().Set("Content-Type", "application/json") w.WriteHeader(status) json.NewEncoder(w).Encode(theResponse) } func FatalError(err error) { fmt.Println(err.Error()) log.Errorf(err.Error()) fmt.Println(". Press Enter to exit...") fmt.Scanln() os.Exit(1) } func FatalErrorWithMail(hotel string, kiosk int, title string, err error) { mail.SendEmailOnError(hotel, kiosk, title, err.Error()) FatalError(err) }