mirror of
https://github.com/KevinMidboe/planetposen-images.git
synced 2025-10-29 13:20:11 +00:00
Implemented logger, write to file on disk
This commit is contained in:
@@ -2,15 +2,16 @@ package handler
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
log "github.com/kevinmidboe/planetposen-images/logger"
|
||||
"net/http"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var logger = log.InitLogger()
|
||||
|
||||
// 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)
|
||||
logger.Error(msg, err)
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
@@ -21,4 +22,19 @@ func handleError(w http.ResponseWriter, err error, msg string, statusCode int, s
|
||||
Error: msg,
|
||||
})
|
||||
w.Write(errorJSON)
|
||||
}
|
||||
}
|
||||
|
||||
func handleGoogleApiError(w http.ResponseWriter, err error, msg string, statusCode int, shouldLog bool) {
|
||||
if shouldLog {
|
||||
logger.GoogleApiError(msg, err)
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(statusCode)
|
||||
errorJSON, _ := json.Marshal(struct {
|
||||
Error string `json:"error"`
|
||||
}{
|
||||
Error: msg,
|
||||
})
|
||||
w.Write(errorJSON)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user