Mail api for sending order confirmation to planetposen customers

This commit is contained in:
2022-12-02 18:26:07 +01:00
commit 2812f6bcbf
13 changed files with 782 additions and 0 deletions

24
server/handler/error.go Normal file
View File

@@ -0,0 +1,24 @@
package handler
import (
"encoding/json"
"net/http"
log "github.com/sirupsen/logrus"
)
// handleError - Logs the error (if shouldLog is true), and outputs the error message (msg)
func handleError(w http.ResponseWriter, err error, msg string, statusCode int, shouldLog bool) {
if shouldLog {
log.WithField("err", err).Error(msg)
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(statusCode)
errorJSON, _ := json.Marshal(struct {
Error string `json:"error"`
}{
Error: msg,
})
w.Write(errorJSON)
}