diff --git a/src/cmd/login.go b/src/cmd/login.go index adc9a43..bdf7a0e 100644 --- a/src/cmd/login.go +++ b/src/cmd/login.go @@ -31,24 +31,24 @@ func loginCmd() *cmdBuilder.Cmd { regions, err := regionRetriever.RetrieveAllFromURL(ctx, cmdData.Params.GetString("regionUrl")) if err != nil { - return err + return errors.Wrap(err, i18n.T(i18n.ErrorRetrievingRegions)) } reg, err := getLoginRegion(ctx, uxBlocks, regions, cmdData.Params.GetString("region")) if err != nil { - return err + return errors.Wrap(err, i18n.T(i18n.ErrorSelectingRegion)) } restApiClient := zeropsRestApiClient.NewAuthorizedClient(cmdData.Args["token"][0], "https://"+reg.Address) response, err := restApiClient.GetUserInfo(ctx) if err != nil { - return err + return errors.Wrap(err, i18n.T(i18n.ErrorGettingUserInfo)) } output, err := response.Output() if err != nil { - return err + return errors.Wrap(err, i18n.T(i18n.ErrorParsingUserInfo)) } _, err = cmdData.CliStorage.Update(func(data cliStorage.Data) cliStorage.Data { @@ -57,7 +57,7 @@ func loginCmd() *cmdBuilder.Cmd { return data }) if err != nil { - return err + return errors.Wrap(err, i18n.T(i18n.ErrorUpdatingCliStorage)) } uxBlocks.PrintInfo(styles.SuccessLine(i18n.T(i18n.LoginSuccess, output.FullName, output.Email))) @@ -103,7 +103,11 @@ func getLoginRegion( uxBlock.SelectTableHeader(header), ) if err != nil { - return region.RegionItem{}, err + return region.RegionItem{}, errors.Wrap(err, i18n.T(i18n.ErrorSelectingRegion)) + } + + if regionIndex[0] < 0 || regionIndex[0] >= len(regions) { + return region.RegionItem{}, errors.New(i18n.T(i18n.ErrorInvalidRegionIndex)) } return regions[regionIndex[0]], nil diff --git a/src/i18n/en.go b/src/i18n/en.go index 5df246f..4576741 100644 --- a/src/i18n/en.go +++ b/src/i18n/en.go @@ -329,4 +329,13 @@ more info: https://docs.zerops.io/references/cli/`, ErrorInvalidScopedProjectId: "Invalid ID of the scoped project [%s], select a different project using `zcli scope project` command.", ErrorInvalidServiceId: "Invalid service ID [%s], %s", // values: serviceId, message ErrorServiceNotFound: "Service [%s] not found", + + // login errors + ErrorRetrievingRegions: "Error retrieving regions", + ErrorSelectingRegion: "Error selecting region", + ErrorGettingUserInfo: "Error getting user information", + ErrorParsingUserInfo: "Error parsing user information", + ErrorUpdatingCliStorage: "Error updating CLI storage", + + ErrorInvalidRegionIndex: "Invalid region index selected", } diff --git a/src/i18n/i18n.go b/src/i18n/i18n.go index 55091c4..2f0bd0d 100644 --- a/src/i18n/i18n.go +++ b/src/i18n/i18n.go @@ -309,4 +309,13 @@ const ( ErrorInvalidScopedProjectId = "ErrorInvalidScopedProjectId" ErrorInvalidServiceId = "ErrorInvalidServiceId" ErrorServiceNotFound = "ErrorServiceNotFound" + + // login errors + ErrorRetrievingRegions = "ErrorRetrievingRegions" + ErrorSelectingRegion = "ErrorSelectingRegion" + ErrorGettingUserInfo = "ErrorGettingUserInfo" + ErrorParsingUserInfo = "ErrorParsingUserInfo" + ErrorUpdatingCliStorage = "ErrorUpdatingCliStorage" + + ErrorInvalidRegionIndex = "ErrorInvalidRegionIndex" )