diff --git a/pkg/httperrors/httperrors.go b/pkg/httperrors/httperrors.go index 224c7dadee..890820ca9d 100644 --- a/pkg/httperrors/httperrors.go +++ b/pkg/httperrors/httperrors.go @@ -35,6 +35,10 @@ func init() { timeZone = time.Local } +func GetTimeZone() *time.Location { + return timeZone +} + func SetTimeZone(tzStr string) { if tz, _ := time.LoadLocation(tzStr); tz != nil { timeZone = tz @@ -51,10 +55,9 @@ func SetHTTPRedirectLocationHeader(w http.ResponseWriter, location string) { } type Error struct { - Code int `json:"code,omitzero"` - Class string `json:"class,omitempty"` - Details string `json:"details,omitempty"` - Time time.Time `json:"time,omitempty"` + Code int `json:"code,omitzero"` + Class string `json:"class,omitempty"` + Details string `json:"details,omitempty"` } func NewErrorFromJCError(ctx context.Context, je *httputils.JSONClientError) Error { @@ -99,9 +102,9 @@ func HTTPError(ctx context.Context, w http.ResponseWriter, msg string, statusCod Code: statusCode, Class: class, Details: details, - Time: time.Now().In(timeZone), } - body := jsonutils.Marshal(err) + body := jsonutils.Marshal(err).(*jsonutils.JSONDict) + body.Set("time", jsonutils.NewString(time.Now().In(timeZone).Format(time.RFC3339))) w.Write([]byte(body.String())) log.Errorf("Send error %s", details) if statusCode >= 500 { diff --git a/pkg/mcclient/modulebase/base.go b/pkg/mcclient/modulebase/base.go index fee7bd575f..2ef6aaa9f7 100644 --- a/pkg/mcclient/modulebase/base.go +++ b/pkg/mcclient/modulebase/base.go @@ -20,9 +20,11 @@ import ( "net/http" "net/url" "strings" + "time" "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/httperrors" "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/util/httputils" ) @@ -243,11 +245,13 @@ type SubmitResult struct { func SubmitResults2JSON(results []SubmitResult) jsonutils.JSONObject { arr := jsonutils.NewArray() + now := time.Now().In(httperrors.GetTimeZone()) for _, r := range results { obj := jsonutils.NewDict() obj.Add(jsonutils.NewInt(int64(r.Status)), "status") obj.Add(jsonutils.Marshal(r.Id), "id") obj.Add(r.Data, "data") + obj.Add(jsonutils.NewString(now.Format(time.RFC3339)), "data", "time") arr.Add(obj) } body := jsonutils.NewDict()