mirror of https://github.com/k3s-io/k3s
Display a better error on unauthorized
Not being logged in is a common user error, and the message we display can be more specific to an end user. Provide a friendly message with the server message in parethesis (in case this is a more complex server error).pull/6/head
parent
a6d9b091c7
commit
dccf114fdd
|
@ -171,10 +171,15 @@ func StandardErrorMessage(err error) (string, bool) {
|
|||
if debugErr, ok := err.(debugError); ok {
|
||||
glog.V(4).Infof(debugErr.DebugError())
|
||||
}
|
||||
_, isStatus := err.(errors.APIStatus)
|
||||
status, isStatus := err.(errors.APIStatus)
|
||||
switch {
|
||||
case isStatus:
|
||||
return fmt.Sprintf("Error from server: %s", err.Error()), true
|
||||
switch s := status.Status(); {
|
||||
case s.Reason == "Unauthorized":
|
||||
return fmt.Sprintf("error: You must be logged in to the server (%s)", s.Message), true
|
||||
default:
|
||||
return fmt.Sprintf("Error from server: %s", err.Error()), true
|
||||
}
|
||||
case errors.IsUnexpectedObjectError(err):
|
||||
return fmt.Sprintf("Server returned an unexpected response: %s", err.Error()), true
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue