func PermissionDeniedErr(e error, msgAndArgs ...interface{}) *Error {
	return err(codes.PermissionDenied, e, msgAndArgs...)
}
PermissionDeniedErr creates an Error with codes.PermissionDenied
package unierr
import (
	"encoding/json"
	"fmt"
	"net/http"
	"github.com/DoNewsCode/core/contract"
	"github.com/DoNewsCode/core/text"
	"github.com/pkg/errors"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
)
func New(code codes.Code, msg string) *Error {
	if code == codes.OK {
		return nil
	}
	return &Error{
		msg:  msg,
		code: code,
	}
}
func Newf(code codes.Code, format string, args ...interface{}) *Error {
	return New(code, fmt.Sprintf(format, args...))
}
func Wrap(err error, code codes.Code) *Error {
	if err == nil {
		return &Error{
			msg:  code.String(),
			code: code,
		}
	}
	err = errors.WithStack(err)
	return &Error{
		err:  err,
		code: code,
		msg:  err.Error(),
	}
}
func Wrapf(err error, code codes.Code, format string, args ...interface{}) *Error {
	se := Wrap(err, code)
	se.msg = format
	se.args = args
	return se
}
type Error struct {
	err  error
	msg  string
	args []interface{}
	code codes.Code
	Printer contract.Printer
	HttpStatusCodeFunc func(code codes.Code) int
}
func (e *Error) UnmarshalJSON(bytes []byte) error {
	var jsonRepresentation struct {
		Code  uint32 `json:"code"`
		Error string `json:"message"`
	}
	if err := json.Unmarshal(bytes, &jsonRepresentation); err != nil {
		return err
	}
	e.code = codes.Code(jsonRepresentation.Code)
	e.msg = jsonRepresentation.Error
	e.err = errors.New(e.msg)
	return nil
}
func (e *Error) MarshalJSON() (result []byte, err error) {
	var jsonRepresentation struct {
		Code  uint32 `json:"code,omitempty"`
		Error string `json:"message"`
	}
	jsonRepresentation.Code = uint32(e.code)
	jsonRepresentation.Error = e.Error()
	return json.Marshal(jsonRepresentation)
}
func (e *Error) Error() string {
	if e.Printer == nil {
		e.Printer = text.BasePrinter{}
	}
	return e.Printer.Sprintf(e.msg, e.args...)
}
func (e *Error) GRPCStatus() *status.Status {
	return status.New(e.code, e.Error())
}
func FromStatus(s *status.Status) *Error {
	return &Error{
		err:  s.Err(),
		msg:  s.Message(),
		code: s.Code(),
	}
}
func (e *Error) StatusCode() int {
	if e.HttpStatusCodeFunc != nil {
		return e.HttpStatusCodeFunc(e.code)
	}
	switch e.code {
	case codes.OK:
		return http.StatusOK
	case codes.Canceled:
		return 499
	case codes.Unknown:
		return http.StatusInternalServerError
	case codes.InvalidArgument:
		return http.StatusBadRequest
	case codes.DeadlineExceeded:
		return http.StatusGatewayTimeout
	case codes.NotFound:
		return http.StatusNotFound
	case codes.AlreadyExists:
		return http.StatusConflict
	case codes.PermissionDenied:
		return http.StatusForbidden
	case codes.ResourceExhausted:
		return http.StatusTooManyRequests
	case codes.FailedPrecondition:
		return http.StatusBadRequest
	case codes.Aborted:
		return http.StatusConflict
	case codes.OutOfRange:
		return http.StatusBadRequest
	case codes.Unimplemented:
		return http.StatusNotImplemented
	case codes.DataLoss:
		return http.StatusInternalServerError
	case codes.Unauthenticated:
		return http.StatusUnauthorized
	default:
		return 500
	}
}
func (e *Error) Unwrap() error {
	return e.err
}
type stackTracer interface {
	StackTrace() errors.StackTrace
}
func (e *Error) StackTrace() errors.StackTrace {
	if e.err == nil {
		return nil
	}
	if err, ok := e.err.(stackTracer); ok {
		return err.StackTrace()
	}
	return errors.WithStack(e.err).(stackTracer).StackTrace()
}
func UnknownErr(e error) *Error {
	return err(codes.Unknown, e)
}
func IsUnknownErr(e error) bool {
	return is(e, codes.Unknown)
}
func CanceledErr(e error, msgAndArgs ...interface{}) *Error {
	return err(codes.Canceled, e, msgAndArgs...)
}
func IsCanceledErr(e error) bool {
	return is(e, codes.Canceled)
}
func DeadlineExceededErr(e error, msgAndArgs ...interface{}) *Error {
	return err(codes.DeadlineExceeded, e, msgAndArgs...)
}
func IsDeadlineExceededErr(e error) bool {
	return is(e, codes.DeadlineExceeded)
}
func AlreadyExistsErr(e error, msgAndArgs ...interface{}) *Error {
	return err(codes.AlreadyExists, e, msgAndArgs...)
}
func IsAlreadyExistsErr(e error) bool {
	return is(e, codes.AlreadyExists)
}
func AbortedErr(e error, msgAndArgs ...interface{}) *Error {
	return err(codes.Aborted, e, msgAndArgs...)
}
func IsAbortedErr(e error) bool {
	return is(e, codes.Aborted)
}
func OutOfRangeErr(e error, msgAndArgs ...interface{}) *Error {
	return err(codes.OutOfRange, e, msgAndArgs...)
}
func IsOutOfRangeErr(e error) bool {
	return is(e, codes.OutOfRange)
}
func UnimplementedErr(e error, msgAndArgs ...interface{}) *Error {
	return err(codes.Unimplemented, e, msgAndArgs...)
}
func IsUnimplementedErr(e error) bool {
	return is(e, codes.Unimplemented)
}
func InternalErr(e error, msgAndArgs ...interface{}) *Error {
	return err(codes.Internal, e, msgAndArgs...)
}
func IsInternalErr(e error) bool {
	return is(e, codes.Internal)
}