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
Clayton Coleman 2016-03-15 12:49:53 -04:00
parent a6d9b091c7
commit dccf114fdd
1 changed files with 7 additions and 2 deletions

View File

@ -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:
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
}