package jsonerr

import "git.rosy.net.cn/baseapi/utils"

type Error struct {
	errCode string
	Obj     interface{}
	ObjStr  string
}

func New(obj interface{}, errCode string) (err *Error) {
	return &Error{
		errCode: errCode,
		Obj:     obj,
		ObjStr:  string(utils.MustMarshal(obj)),
	}
}

func IsJsonErr(err error) bool {
	_, ok := err.(*Error)
	return ok
}

func (e *Error) Error() string {
	return e.ObjStr
}

func (e *Error) ErrCode() string {
	return e.errCode
}
