func NewCodedError(err error, code Code) CodedError {
	if err == nil {
		panic("NewCodedError error is nil")
	}
	if errcode, ok := err.(ErrorCode); ok {
		code = errcode.Code()
	}
	return CodedError{GetCode: code, Err: err}
}
NewCodedError is for constructing broad error kinds (e.g. those representing HTTP codes)
Which could have many different underlying go errors.
Eventually you may want to give your go errors more specific codes.
The second argument is the broad code.

If the error given is already an ErrorCode,
that will be used as the code instead of the second argument.
package errcode
import (
	"fmt"
	"net/http"
)
var (
	InternalCode = NewCode("internal").SetHTTP(http.StatusInternalServerError)
	NotFoundCode = NewCode("missing").SetHTTP(http.StatusNotFound)
	UnimplementedCode = InternalCode.Child("internal.unimplemented").SetHTTP(http.StatusNotImplemented)
	StateCode = NewCode("state").SetHTTP(http.StatusBadRequest)
	AlreadyExistsCode = StateCode.Child("state.exists").SetHTTP(http.StatusConflict)
	OutOfRangeCode = StateCode.Child("state.range")
	InvalidInputCode = NewCode("input").SetHTTP(http.StatusBadRequest)
	AuthCode = NewCode("auth")
	NotAuthenticatedCode = AuthCode.Child("auth.unauthenticated").SetHTTP(http.StatusUnauthorized)
	ForbiddenCode = AuthCode.Child("auth.forbidden").SetHTTP(http.StatusForbidden)
)
type invalidInputErr struct{ CodedError }
func NewInvalidInputErr(err error) ErrorCode {
	return invalidInputErr{NewCodedError(err, InvalidInputCode)}
}
var _ ErrorCode = (*invalidInputErr)(nil)      
var _ HasClientData = (*invalidInputErr)(nil)  
var _ Causer = (*invalidInputErr)(nil)         
type internalErr struct{ StackCode }
var internalStackCode = makeInternalStackCode(InternalCode)
func NewInternalErr(err error) ErrorCode {
	return internalErr{internalStackCode(err)}
}
var _ ErrorCode = (*internalErr)(nil)      
var _ HasClientData = (*internalErr)(nil)  
var _ Causer = (*internalErr)(nil)         
func makeInternalStackCode(defaultCode Code) func(error) StackCode {
	if !defaultCode.IsAncestor(InternalCode) {
		panic(fmt.Errorf("code is not an internal code: %v", defaultCode))
	}
	return func(err error) StackCode {
		if err == nil {
			panic("makeInternalStackCode error is nil")
		}
		code := defaultCode
		if errcode, ok := err.(ErrorCode); ok {
			errCode := errcode.Code()
			if errCode.IsAncestor(InternalCode) {
				code = errCode
			}
		}
		return NewStackCode(CodedError{GetCode: code, Err: err}, 3)
	}
}
type unimplementedErr struct{ StackCode }
var unimplementedStackCode = makeInternalStackCode(UnimplementedCode)
func NewUnimplementedErr(err error) ErrorCode {
	return unimplementedErr{unimplementedStackCode(err)}
}
type notFoundErr struct{ CodedError }
func NewNotFoundErr(err error) ErrorCode {
	return notFoundErr{NewCodedError(err, NotFoundCode)}
}
var _ ErrorCode = (*notFoundErr)(nil)      
var _ HasClientData = (*notFoundErr)(nil)  
var _ Causer = (*notFoundErr)(nil)         
type notAuthenticatedErr struct{ CodedError }
func NewNotAuthenticatedErr(err error) ErrorCode {
	return notAuthenticatedErr{NewCodedError(err, NotAuthenticatedCode)}
}
var _ ErrorCode = (*notAuthenticatedErr)(nil)      
var _ HasClientData = (*notAuthenticatedErr)(nil)  
var _ Causer = (*notAuthenticatedErr)(nil)         
type forbiddenErr struct{ CodedError }
func NewForbiddenErr(err error) ErrorCode {
	return forbiddenErr{NewCodedError(err, ForbiddenCode)}
}
var _ ErrorCode = (*forbiddenErr)(nil)      
var _ HasClientData = (*forbiddenErr)(nil)  
var _ Causer = (*forbiddenErr)(nil)         
type CodedError struct {
	GetCode Code
	Err     error
}