func New(errorCode ErrorCode, cause error) Error {
	return Error{cause: cause, errorCode: errorCode}
}
New creates a new instance of an error
package errors
import (
	"fmt"
	"github.com/oasislabs/oasis-gateway/log"
	stderr "github.com/pkg/errors"
)
type Err interface {
	Error() string
	Cause() error
	StackTrace() stderr.StackTrace
	ErrorCode() ErrorCode
	log.Loggable
}
var (
	ErrInternalError = ErrorCode{
		category: InternalError,
		code:     1000,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrInvalidStateChangeError = ErrorCode{
		category: InternalError,
		code:     1001,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrEstimateGas = ErrorCode{
		category: InternalError,
		code:     1002,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrSignedTx = ErrorCode{
		category: InternalError,
		code:     1003,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrSendTransaction = ErrorCode{
		category: InternalError,
		code:     1004,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrTransactionReceipt = ErrorCode{
		category: InternalError,
		code:     1005,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrTransactionReceiptStatus = ErrorCode{
		category: InternalError,
		code:     1006,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrFetchNonce = ErrorCode{
		category: InternalError,
		code:     1007,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrMaxAttemptsReached = ErrorCode{
		category: InternalError,
		code:     1008,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrEkidenDial = ErrorCode{
		category: InternalError,
		code:     1009,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrEkidenParseCertificate = ErrorCode{
		category: InternalError,
		code:     1009,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrEkidenGetCommittee = ErrorCode{
		category: InternalError,
		code:     1011,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrEkidenCommitteeKindUndefined = ErrorCode{
		category: InternalError,
		code:     1012,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrEkidenCommitteeNotFound = ErrorCode{
		category: InternalError,
		code:     1013,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrEkidenCommitteeLeaderNotFound = ErrorCode{
		category: InternalError,
		code:     1014,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrEkidenGetNode = ErrorCode{
		category: InternalError,
		code:     1015,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrEkidenParseNodeCertificate = ErrorCode{
		category: InternalError,
		code:     1016,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrEkidenNodeNoAddress = ErrorCode{
		category: InternalError,
		code:     1017,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrEkidenPortInvalid = ErrorCode{
		category: InternalError,
		code:     1019,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrEkidenAddressInvalid = ErrorCode{
		category: InternalError,
		code:     1019,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrEkidenAddressTransportUnsupported = ErrorCode{
		category: InternalError,
		code:     1020,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrEkidenEncodeTx = ErrorCode{
		category: InternalError,
		code:     1021,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrEkidenSubmitTx = ErrorCode{
		category: InternalError,
		code:     1022,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrEkidenEncodeRLPTx = ErrorCode{
		category: InternalError,
		code:     1023,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrEkidenSignTx = ErrorCode{
		category: InternalError,
		code:     1024,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrEkidenDecodeResponse = ErrorCode{
		category: InternalError,
		code:     1025,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrEkidenEmptyResponse = ErrorCode{
		category: InternalError,
		code:     1026,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrEkidenGetPublicKey = ErrorCode{
		category: InternalError,
		code:     1027,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrQueueRetrieve = ErrorCode{
		category: InternalError,
		code:     1028,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrQueueRemove = ErrorCode{
		category: InternalError,
		code:     1029,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrQueueDiscard = ErrorCode{
		category: InternalError,
		code:     1030,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrQueueInsert = ErrorCode{
		category: InternalError,
		code:     1031,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrSignTransaction = ErrorCode{
		category: InternalError,
		code:     1032,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrExecuteTransaction = ErrorCode{
		category: InternalError,
		code:     1033,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrGetExpiry = ErrorCode{
		category: InternalError,
		code:     1034,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrGetPublicKey = ErrorCode{
		category: InternalError,
		code:     1035,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrRemoveWallet = ErrorCode{
		category: InternalError,
		code:     1036,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrQueueNext = ErrorCode{
		category: InternalError,
		code:     1037,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrUnkownEventType = ErrorCode{
		category: InternalError,
		code:     1038,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrDeserializeEvent = ErrorCode{
		category: InternalError,
		code:     1039,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrGetBalance = ErrorCode{
		category: InternalError,
		code:     1040,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrGetServiceCode = ErrorCode{
		category: InternalError,
		code:     1041,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrServiceCodeNotDeployed = ErrorCode{
		category: InternalError,
		code:     1042,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrQueueExists = ErrorCode{
		category: InternalError,
		code:     1043,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrEkidenGetCode = ErrorCode{
		category: InternalError,
		code:     1044,
		desc:     "Internal Error. Please check the status of the service.",
	}
	ErrOutOfRange = ErrorCode{
		category: InputError,
		code:     2001,
		desc:     "Out of range. Provided value is out of the allowed range.",
	}
	ErrHttpContentLengthMissing = ErrorCode{
		category: InputError,
		code:     2002,
		desc:     "Content-length header missing from request.",
	}
	ErrHttpContentLengthLimit = ErrorCode{
		category: InputError,
		code:     2003,
		desc:     "Content-length exceeds request limit.",
	}
	ErrHttpContentTypeApplicationJson = ErrorCode{
		category: InputError,
		code:     2004,
		desc:     "Content-type should be application/json.",
	}
	ErrDeserializeJSON = ErrorCode{
		category: InputError,
		code:     2005,
		desc:     "Failed to deserialize body as JSON.",
	}
	ErrInvalidAddress = ErrorCode{
		category: InputError,
		code:     2006,
		desc:     "Provided invalid address.",
	}
	ErrEmptyInput = ErrorCode{
		category: InputError,
		code:     2007,
		desc:     "Input cannot be empty.",
	}
	ErrUnknownSubscriptionType = ErrorCode{
		category: InputError,
		code:     2008,
		desc:     "Unknown subscription type.",
	}
	ErrParseQueryParams = ErrorCode{
		category: InputError,
		code:     2009,
		desc:     "Failed to parse query parameters.",
	}
	ErrSubscribeFilterAddress = ErrorCode{
		category: InputError,
		code:     2010,
		desc:     "Only address is available at this time for filtering.",
	}
	ErrInvalidKey = ErrorCode{
		category: InputError,
		code:     2011,
		desc:     "Provided invalid key.",
	}
	ErrTopicLogsSupported = ErrorCode{
		category: InputError,
		code:     2012,
		desc:     "Only logs topic supported for subscriptions.",
	}
	ErrStringNotHex = ErrorCode{
		category: InputError,
		code:     2013,
		desc:     "Provided string is not a valid hex encoding.",
	}
	ErrQueueLimitReached = ErrorCode{
		category: ResourceLimitReached,
		code:     3001,
		desc: "The number of unconfirmed requests has reached its limit. " +
			"No further requests can be processed until requests are confirmed.",
	}
	ErrQueueDiscardNotExists = ErrorCode{
		category: StateConflict,
		code:     4001,
		desc:     "Attempt to discard elements from a queue that does not exist.",
	}
	ErrSubscriptionAlreadyExists = ErrorCode{
		category: StateConflict,
		code:     4002,
		desc:     "Attempt to create a subscription that already exists.",
	}
	ErrAPINotImplemented = ErrorCode{
		category: NotImplemented,
		code:     5001,
		desc:     "API not Implemented.",
	}
	ErrQueueNotFound = ErrorCode{
		category: NotFound,
		code:     6001,
		desc:     "Queue not found.",
	}
	ErrSubscriptionNotFound = ErrorCode{
		category: NotFound,
		code:     6002,
		desc:     "Subscription not found.",
	}
	ErrInvalidAAD = ErrorCode{
		category: AuthenticationError,
		code:     7001,
		desc:     "Provided AAD is not valid.",
	}
	ErrFailedAADVerification = ErrorCode{
		category: AuthenticationError,
		code:     7002,
		desc:     "Failed to verify AAD in transaction data.",
	}
	ErrAuthenticateRequest = ErrorCode{
		category: AuthenticationError,
		code:     7003,
		desc:     "Failed to authenticate request.",
	}
	ErrVerifyRequest = ErrorCode{
		category: AuthenticationError,
		code:     7004,
		desc:     "Failed to verify request.",
	}
)
type Category string
const (
	InternalError Category = "InternalError"
	InputError Category = "InputError"
	StateConflict Category = "StateConflict"
	ResourceLimitReached Category = "ResourceLimitReached"
	NotFound Category = "NotFound"
	NotImplemented Category = "Not Implemented"
	AuthenticationError Category = "AuthenticationError"
)
type stackTracer interface {
	StackTrace() stderr.StackTrace
}
type causer interface {
	Cause() error
}
type Error struct {
	cause     error
	errorCode ErrorCode
}
func (e Error) Error() string {
	if e.cause == nil {
		return fmt.Sprintf("[%d] error code %s with desc %s",
			e.errorCode.Code(), e.errorCode.Category(), e.errorCode.Desc())
	} else {
		return fmt.Sprintf("[%d] error code %s with desc %s with cause %s",
			e.errorCode.Code(), e.errorCode.Category(), e.errorCode.Desc(), e.cause)
	}
}
func (e Error) Log(fields log.Fields) {
	fields.Add("err", e.errorCode.Desc())
	fields.Add("errorCode", e.errorCode.Code())
	stackErr, ok := e.cause.(stackTracer)
	if ok {
		fields.Add("stack", stackErr.StackTrace())
	}
	causerErr, ok := e.cause.(causer)
	if ok {
		cause := causerErr.Cause()
		loggableCause, ok := cause.(Error)  
		if ok {
			loggableCause.Log(fields)
		}
		fields.Add("cause", cause)
	} else {
		if e.cause != nil {
			fields.Add("cause", e.cause)
		}
	}
}
func (e Error) Cause() error {
	if causerErr, ok := e.cause.(causer); ok {
		return causerErr.Cause()
	}
	return e.cause
}
func (e Error) StackTrace() stderr.StackTrace {
	if stErr, ok := e.cause.(stackTracer); ok {
		return stErr.StackTrace()
	}
	return nil
}
func (e Error) ErrorCode() ErrorCode {
	return e.errorCode
}