package atp import ( "errors" "fmt" "strings" ) // ErrSessionExpired indicates the OAuth session can no longer be resumed. // Callers should prompt the user to re-authenticate. var ErrSessionExpired = errors.New("oauth session expired") // WrapPDSError inspects an XRPC error for signals that the OAuth grant is no // longer valid and, if so, wraps it with ErrSessionExpired. // TODO: handle other common error types func WrapPDSError(err error) error { if err == nil { return nil } msg := err.Error() if strings.Contains(msg, "invalid_grant") || strings.Contains(msg, "failed to refresh OAuth tokens") || strings.Contains(msg, "token is expired") { return fmt.Errorf("%w: %w", ErrSessionExpired, err) } return err }