File size: 1,590 Bytes
7259a41 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
package errors
import (
"fmt"
"strconv"
)
// ConfigError is returned when a configuration field is invalid.
type ConfigError struct {
Field string
Reason string
}
func (c ConfigError) Error() string {
return fmt.Sprintf("invalid config: %s: %s", c.Field, c.Reason)
}
// ConnectError is returned when the client fails to connect to the server.
type ConnectError struct {
Err error
}
func (c ConnectError) Error() string {
return "connect error: " + c.Err.Error()
}
func (c ConnectError) Unwrap() error {
return c.Err
}
// AuthError is returned when the client fails to authenticate with the server.
type AuthError struct {
StatusCode int
}
func (a AuthError) Error() string {
return "authentication error, HTTP status code: " + strconv.Itoa(a.StatusCode)
}
// DialError is returned when the server rejects the client's dial request.
// This applies to both TCP and UDP.
type DialError struct {
Message string
}
func (c DialError) Error() string {
return "dial error: " + c.Message
}
// ClosedError is returned when the client attempts to use a closed connection.
type ClosedError struct {
Err error // Can be nil
}
func (c ClosedError) Error() string {
if c.Err == nil {
return "connection closed"
} else {
return "connection closed: " + c.Err.Error()
}
}
func (c ClosedError) Unwrap() error {
return c.Err
}
// ProtocolError is returned when the server/client runs into an unexpected
// or malformed request/response/message.
type ProtocolError struct {
Message string
}
func (p ProtocolError) Error() string {
return "protocol error: " + p.Message
}
|