@@ -13,7 +13,7 @@ import (
1313const (
1414 // Authentication & Authorization Errors (2000-2099)
1515 ErrorCodeUnauthorized = 2000
16- ErrorCodeInvalidToken = 2001
16+ ErrorCodeInvalidToken = 2001 // Used for expired tokens
1717 ErrorCodeInvalidUserCode = 2002
1818 ErrorCodeTokenNotFound = 2003
1919 ErrorCodeInvalidDeviceCode = 2004
@@ -42,15 +42,9 @@ type AppErrorDetail struct {
4242 StatusCode int `json:"status_code"`
4343}
4444
45- // ErrorResponse represents an error response from the API
46- // Supports both new format (error object) and legacy format (error string)
45+ // ErrorResponse represents an error response from the API (new format only)
4746type ErrorResponse struct {
48- // New format
4947 Error * AppErrorDetail `json:"error,omitempty"`
50-
51- // Legacy format (for backward compatibility)
52- ErrorString string `json:"error_description,omitempty"`
53- Message string `json:"message,omitempty"`
5448}
5549
5650// APIError represents an API error with status code and message
@@ -153,6 +147,11 @@ func IsForceUpgrade(err error) bool {
153147 return errors .As (err , & forceUpgradeErr )
154148}
155149
150+ // IsTokenExpired checks if the error is a token expiration error
151+ func IsTokenExpired (err error ) bool {
152+ return HasErrorCode (err , ErrorCodeInvalidToken )
153+ }
154+
156155// CheckErr checks for errors and prints appropriate messages using the command's output
157156// Returns true if no error (ok to continue), false if there was an error
158157func CheckErr (cmd * cobra.Command , err error ) bool {
@@ -181,6 +180,27 @@ func CheckErr(cmd *cobra.Command, err error) bool {
181180 return false
182181 }
183182
183+ // Check if it's a token expiration error
184+ if IsTokenExpired (err ) {
185+ // Create styled error message box
186+ errorStyle := lipgloss .NewStyle ().
187+ Bold (true ).
188+ Foreground (lipgloss .Color ("#FF5F87" )).
189+ Padding (1 , 2 ).
190+ Border (lipgloss .RoundedBorder ()).
191+ BorderForeground (lipgloss .Color ("#FF5F87" ))
192+
193+ commandStyle := lipgloss .NewStyle ().
194+ Bold (true ).
195+ Foreground (lipgloss .Color ("#87D7FF" ))
196+
197+ message := fmt .Sprintf ("Your session has expired!\n \n Run %s to login again." ,
198+ commandStyle .Render ("major user login" ))
199+
200+ cmd .Println (errorStyle .Render (message ))
201+ return false
202+ }
203+
184204 // Check if it's a no token error
185205 if IsNoToken (err ) {
186206 // Create styled error message box
0 commit comments