mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2026-03-17 21:37:30 +01:00
Include calling function in error message
Entire-Checkpoint: a4948d0fe7a3
This commit is contained in:
@@ -16,6 +16,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@@ -184,7 +185,8 @@ type DefaultAPIResponse struct {
|
|||||||
// handleError writes a standardized JSON error response with the given status code.
|
// handleError writes a standardized JSON error response with the given status code.
|
||||||
// It logs the error at WARN level and ensures proper Content-Type headers are set.
|
// It logs the error at WARN level and ensures proper Content-Type headers are set.
|
||||||
func handleError(err error, statusCode int, rw http.ResponseWriter) {
|
func handleError(err error, statusCode int, rw http.ResponseWriter) {
|
||||||
cclog.Warnf("REST ERROR : %s", err.Error())
|
_, file, line, _ := runtime.Caller(1)
|
||||||
|
cclog.Warnf("REST ERROR (%s:%d): %s", filepath.Base(file), line, err.Error())
|
||||||
rw.Header().Add("Content-Type", "application/json")
|
rw.Header().Add("Content-Type", "application/json")
|
||||||
rw.WriteHeader(statusCode)
|
rw.WriteHeader(statusCode)
|
||||||
if err := json.NewEncoder(rw).Encode(ErrorResponse{
|
if err := json.NewEncoder(rw).Encode(ErrorResponse{
|
||||||
|
|||||||
Reference in New Issue
Block a user