package hpds_err import ( "fmt" quic "github.com/quic-go/quic-go" ) // HpdsError hpds error type HpdsError interface { error // ErrorCode getter method ErrorCode() ErrorCode } type hpdsError struct { errorCode ErrorCode err error } // New create hpds error func New(code ErrorCode, err error) HpdsError { return &hpdsError{ errorCode: code, err: err, } } func (e *hpdsError) Error() string { return fmt.Sprintf("%s error: message=%s", e.errorCode, e.err.Error()) } // ErrorCode getter method func (e *hpdsError) ErrorCode() ErrorCode { return e.errorCode } // ErrorCode error code type ErrorCode uint64 const ( // ErrorCodeClientAbort client abort ErrorCodeClientAbort ErrorCode = 0xC7 // ErrorCodeUnknown unknown error ErrorCodeUnknown ErrorCode = 0xC0 // ErrorCodeClosed net closed ErrorCodeClosed ErrorCode = 0xC1 // ErrorCodeBeforeHandler before handler ErrorCodeBeforeHandler ErrorCode = 0xC2 // ErrorCodeMainHandler main handler ErrorCodeMainHandler ErrorCode = 0xC3 // ErrorCodeAfterHandler after handler ErrorCodeAfterHandler ErrorCode = 0xC4 // ErrorCodeHandshake handshake frame ErrorCodeHandshake ErrorCode = 0xC5 // ErrorCodeRejected server rejected ErrorCodeRejected ErrorCode = 0xCC // ErrorCodeGoaway goaway frame ErrorCodeGoaway ErrorCode = 0xCF // ErrorCodeData data frame ErrorCodeData ErrorCode = 0xCE // ErrorCodeUnknownClient unknown client error ErrorCodeUnknownClient ErrorCode = 0xCD // ErrorCodeDuplicateName unknown client error ErrorCodeDuplicateName ErrorCode = 0xC6 ErrorCodeStartHandler ErrorCode = 0xC8 ) func (e ErrorCode) String() string { switch e { case ErrorCodeClientAbort: return "ClientAbort" case ErrorCodeUnknown: return "UnknownError" case ErrorCodeClosed: return "NetClosed" case ErrorCodeBeforeHandler: return "BeforeHandler" case ErrorCodeMainHandler: return "MainHandler" case ErrorCodeAfterHandler: return "AfterHandler" case ErrorCodeHandshake: return "Handshake" case ErrorCodeRejected: return "Rejected" case ErrorCodeGoaway: return "Goaway" case ErrorCodeData: return "DataFrame" case ErrorCodeUnknownClient: return "UnknownClient" case ErrorCodeDuplicateName: return "DuplicateName" case ErrorCodeStartHandler: return "StartHandler" default: return "XXX" } } // Is parse quic ApplicationErrorCode to hpds ErrorCode func Is(he quic.ApplicationErrorCode, err ErrorCode) bool { return uint64(he) == uint64(err) } // Parse parse quic ApplicationErrorCode func Parse(err quic.ApplicationErrorCode) ErrorCode { return ErrorCode(err) } // To convert hpds ErrorCode to quic ApplicationErrorCode func (e ErrorCode) To() quic.ApplicationErrorCode { return quic.ApplicationErrorCode(e) } // DuplicateNameError duplicate name(sfn) type DuplicateNameError struct { connId string err error } // NewDuplicateNameError create a duplicate name error func NewDuplicateNameError(connId string, err error) DuplicateNameError { return DuplicateNameError{ connId: connId, err: err, } } // Error raw error func (e DuplicateNameError) Error() string { return e.err.Error() } // ErrorCode getter method func (e DuplicateNameError) ErrorCode() ErrorCode { return ErrorCodeDuplicateName } // ConnId duplicate connection ID func (e DuplicateNameError) ConnId() string { return e.connId }