mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
bug: Cleaner error message for non logged-in users (#1670)
* add helper text to unauthorized error messages * fix lint error, add unit tests * fix test name * fix test name * fix lint errors in test * add unauthorized test for templates create * remove unnecessary variable * remove Error struct, change error message * change [url] to <url>
This commit is contained in:
+10
@@ -7,6 +7,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/kirsle/configdir"
|
||||
"github.com/mattn/go-isatty"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -113,6 +115,10 @@ func createClient(cmd *cobra.Command) (*codersdk.Client, error) {
|
||||
if err != nil || rawURL == "" {
|
||||
rawURL, err = root.URL().Read()
|
||||
if err != nil {
|
||||
// If the configuration files are absent, the user is logged out
|
||||
if os.IsNotExist(err) {
|
||||
return nil, xerrors.New("You are not logged in. Try logging in using 'coder login <url>'.")
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@@ -124,6 +130,10 @@ func createClient(cmd *cobra.Command) (*codersdk.Client, error) {
|
||||
if err != nil || token == "" {
|
||||
token, err = root.Session().Read()
|
||||
if err != nil {
|
||||
// If the configuration files are absent, the user is logged out
|
||||
if os.IsNotExist(err) {
|
||||
return nil, xerrors.New("You are not logged in. Try logging in using 'coder login <url>'.")
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user