diff --git a/internal/cloudapi/v2/errors.go b/internal/cloudapi/v2/errors.go index 11ae42e4a..90c8ae537 100644 --- a/internal/cloudapi/v2/errors.go +++ b/internal/cloudapi/v2/errors.go @@ -224,18 +224,17 @@ func apiErrorFromEchoError(echoError *echo.HTTPError) ServiceErrorCode { // Convert an echo error into an AOC compliant one so we send a correct json error response func (s *Server) HTTPErrorHandler(echoError error, c echo.Context) { - doResponse := func(code ServiceErrorCode, c echo.Context) { + doResponse := func(code ServiceErrorCode, c echo.Context, internal error) { if !c.Response().Committed { var err error sec := find(code) apiErr := APIError(code, sec, c) if sec.httpStatus == http.StatusInternalServerError { - internalError, ok := echoError.(*echo.HTTPError) errMsg := fmt.Sprintf("Internal server error. Code: %s, OperationId: %s", apiErr.Code, apiErr.OperationId) - if ok { - errMsg += fmt.Sprintf(", InternalError: %v", internalError) + if internal != nil { + errMsg += fmt.Sprintf(", InternalError: %v", internal) } c.Logger().Error(errMsg) @@ -257,7 +256,7 @@ func (s *Server) HTTPErrorHandler(echoError error, c echo.Context) { he, ok := echoError.(*echo.HTTPError) if !ok { c.Logger().Errorf("ErrorNotHTTPError %v", echoError) - doResponse(ErrorNotHTTPError, c) + doResponse(ErrorNotHTTPError, c, echoError) return } @@ -271,8 +270,8 @@ func (s *Server) HTTPErrorHandler(echoError error, c echo.Context) { sec, ok := he.Message.(ServiceErrorCode) if !ok { // No service code was set, so Echo threw this error - doResponse(apiErrorFromEchoError(he), c) + doResponse(apiErrorFromEchoError(he), c, he.Internal) return } - doResponse(sec, c) + doResponse(sec, c, he.Internal) } diff --git a/internal/worker/api/errors.go b/internal/worker/api/errors.go index d3ca9b295..25b1571e3 100644 --- a/internal/worker/api/errors.go +++ b/internal/worker/api/errors.go @@ -155,11 +155,11 @@ func HTTPErrorHandler(echoError error, c echo.Context) { apiErr := APIError(code, sec, c) if sec.httpStatus == http.StatusInternalServerError { - c.Logger().Errorf("Internal server error. Internal: %s, Code: %s, OperationId: %s", + c.Logger().Errorf("Internal server error. Internal: %v, Code: %s, OperationId: %s", internal, apiErr.Code, apiErr.OperationId) } else { - c.Logger().Infof("%s, Code: %s, OperationId: %s", internal, - apiErr.Code, apiErr.OperationId) + c.Logger().Infof("Code: %s, OperationId: %s, Internal: %v", + apiErr.Code, apiErr.OperationId, internal) } if c.Request().Method == http.MethodHead { @@ -168,7 +168,7 @@ func HTTPErrorHandler(echoError error, c echo.Context) { err = c.JSON(sec.httpStatus, apiErr) } if err != nil { - c.Logger().Error(err) + c.Logger().Errorf("Failed to return error response: %v", err) } } } @@ -185,5 +185,5 @@ func HTTPErrorHandler(echoError error, c echo.Context) { doResponse(apiErrorFromEchoError(he), c, he.Internal) return } - doResponse(sec, c, nil) + doResponse(sec, c, he.Internal) }