move all error things to new qerr package, replacing errorcodes

This commit is contained in:
Lucas Clemente
2016-05-17 10:24:34 +02:00
parent 62da35d613
commit bfaa4200df
12 changed files with 71 additions and 66 deletions

30
qerr/quic_error.go Normal file
View File

@@ -0,0 +1,30 @@
package qerr
import (
"fmt"
)
// ErrorCode can be used as a normal error without reason.
type ErrorCode uint32
func (e ErrorCode) Error() string {
return e.String()
}
// A QuicError consists of an error code plus a error reason
type QuicError struct {
ErrorCode ErrorCode
ErrorMessage string
}
// Error creates a new QuicError instance
func Error(errorCode ErrorCode, errorMessage string) *QuicError {
return &QuicError{
ErrorCode: errorCode,
ErrorMessage: errorMessage,
}
}
func (e *QuicError) Error() string {
return fmt.Sprintf("%s: %s", e.ErrorCode.String(), e.ErrorMessage)
}