* add new error funcs which take a ctx and deprecate existing funcs * use context where available when writing error events * remove circular internal/errors pkg dep * suppress some chatty errors using errors.WithoutEvent() * convert auth oidc funcs to take context where needed to write events Co-authored-by: Jim <jlambert@hashicorp.com>
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package session
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/boundary/internal/errors"
|
|
)
|
|
|
|
// ClosedReason of the connection
|
|
type ClosedReason string
|
|
|
|
const (
|
|
UnknownReason ClosedReason = "unknown"
|
|
ConnectionTimedOut ClosedReason = "timed out"
|
|
ConnectionClosedByUser ClosedReason = "closed by end-user"
|
|
ConnectionCanceled ClosedReason = "canceled"
|
|
ConnectionNetworkError ClosedReason = "network error"
|
|
ConnectionSystemError ClosedReason = "system error"
|
|
)
|
|
|
|
// String representation of the termination reason
|
|
func (r ClosedReason) String() string {
|
|
return string(r)
|
|
}
|
|
|
|
func convertToClosedReason(s string) (ClosedReason, error) {
|
|
const op = "session.convertToClosedReason"
|
|
switch s {
|
|
case UnknownReason.String():
|
|
return UnknownReason, nil
|
|
case ConnectionTimedOut.String():
|
|
return ConnectionTimedOut, nil
|
|
case ConnectionClosedByUser.String():
|
|
return ConnectionClosedByUser, nil
|
|
case ConnectionCanceled.String():
|
|
return ConnectionCanceled, nil
|
|
case ConnectionNetworkError.String():
|
|
return ConnectionNetworkError, nil
|
|
case ConnectionSystemError.String():
|
|
return ConnectionSystemError, nil
|
|
default:
|
|
return "", errors.NewDeprecated(errors.InvalidParameter, op, fmt.Sprintf("%s is not a valid reason", s))
|
|
}
|
|
}
|