package errHandler

import (
	"github.com/gogf/gf/v2/errors/gcode"
	"github.com/gogf/gf/v2/errors/gerror"
	"github.com/gogf/gf/v2/os/glog"
	"golang.org/x/net/context"
)

func WrapError(ctx context.Context, code gcode.Code, err error, message ...string) error {
	if err == nil {
		return nil
	}
	newMsg := ""
	glog.Error(ctx, "错误", err)
	if len(message) != 0 {
		newMsg = message[0]
	} else {
		newMsg = code.Message()
	}
	return gerror.NewCode(code, newMsg)
}
