on main help sign in
chore: add custom error and message for hyper unauthorized (#2577)
commit1b7a457f279e9726032ac92b7ccfe4ee17479ffb authorAndrey Nering <andreynering@users.noreply.github.com> dateTue 7 Apr 2026, 17:00 (6 months ago) parentf1c7fe4
3 files changed+8−3
internal/agent/agent.go+2 internal/agent/hyper/provider.go+5−2 internal/ui/model/ui.go+1−1
internal/agent/agent.go+2
@@ -529,6 +529,8 @@ func (a *sessionAgent) Run(ctx context.Context, call SessionAgentCall) (*fantasy
529529 currentAssistant.AddFinish(message.FinishReasonCanceled, "User canceled request", "")
530530 } else if isPermissionErr {
531531 currentAssistant.AddFinish(message.FinishReasonPermissionDenied, "User denied permission", "")
532+ } else if errors.Is(err, hyper.ErrUnauthorized) {
533+ currentAssistant.AddFinish(message.FinishReasonError, "Unauthorized", `Authentication with Hyper failed. Please run "crush auth" to re-authenticate.`)
532534 } else if errors.Is(err, hyper.ErrNoCredits) {
533535 url := hyper.BaseURL()
534536 link := linkStyle.Hyperlink(url, "id=hyper").Render(url)
internal/agent/hyper/provider.go+5−2
@@ -69,7 +69,10 @@ var BaseURL = sync.OnceValue(func() string {
6969 return cmp.Or(os.Getenv("HYPER_URL"), defaultBaseURL)
7070})
7171
72−var ErrNoCredits = errors.New("you're out of credits")
72+var (
73+ ErrNoCredits = errors.New("you're out of credits")
74+ ErrUnauthorized = errors.New("unauthorized")
75+)
7376
7477type options struct {
7578 baseURL string
@@ -183,7 +186,7 @@ func (m *languageModel) Stream(ctx context.Context, call fantasy.Call) (fantasy.
183186 return nil, toProviderError(resp, retryAfter(resp))
184187 case http.StatusUnauthorized:
185188 _ = resp.Body.Close()
186− return nil, toProviderError(resp, "")
189+ return nil, ErrUnauthorized
187190 case http.StatusPaymentRequired:
188191 _ = resp.Body.Close()
189192 return nil, ErrNoCredits
internal/ui/model/ui.go+1−1
@@ -2964,7 +2964,7 @@ func (m *UI) sendMessage(content string, attachments ...message.Attachment) tea.
29642964 }
29652965 return util.InfoMsg{
29662966 Type: util.InfoTypeError,
2967− Msg: fmt.Sprintf("Failed to run agent: %v", err),
2967+ Msg: fmt.Sprintf("%v", err),
29682968 }
29692969 }
29702970 return nil