Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug - Sagiri] SagiriService - StartAsync() で例外がキャッチできない #28

Open
Asteriskx opened this issue Feb 11, 2024 · 0 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request Next-Release Next-Release

Comments

@Asteriskx
Copy link
Contributor

      var pollingTask = Task.Run(() =>
      {
          var observer = Observable.Interval(TimeSpan.FromSeconds(1))
              .Select(async _ => _CurrentlyPlaying = await _spotifyClient?.Player?.GetCurrentlyPlaying(new()))
              .Select(track => CurrentTrackInfo.GetCurrentTrackInfo(_CurrentlyPlaying))
              .Distinct()
              .Where(track => track is not null)
              .Subscribe(track => _CurrentTrackChanged?.Invoke(track));

          if (ct.IsCancellationRequested)
          {
              observer.Dispose();
              _CurrentTrackErrorDetected.Invoke();
          }

          _Logger.WriteLog("[SpotifyService] - Polling Start....", Logger.LogLevel.Debug);
      }, ct);

      try
      {
          await pollingTask;
      }
      catch (Exception ex)
      {
          if (pollingTask.Exception is AggregateException agex)
          {
              agex.Handle((exp) =>
              {
                  agex.InnerExceptions.ToList().ForEach((ages) => {
                      _Logger.WriteLog($"[SpotifyService] - Polling error... {ages.Message}", Logger.LogLevel.Error);
                  });

                  // If you set it to true, the exception will not be thrown again because it has already been handled.
                  // Or else, the exception will be re-throw as it is still unhandled.
                  return false;
              });
          }
      }
@Asteriskx Asteriskx added bug Something isn't working enhancement New feature or request Next-Release Next-Release labels Feb 11, 2024
@Asteriskx Asteriskx self-assigned this Feb 11, 2024
@Asteriskx Asteriskx changed the title [Sagiri] SagiriService - StartAsync() で例外がキャッチできない [Bug - Sagiri] SagiriService - StartAsync() で例外がキャッチできない Jun 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request Next-Release Next-Release
Projects
None yet
Development

No branches or pull requests

1 participant