1717using System . Reactive ;
1818using System . Diagnostics . CodeAnalysis ;
1919using Octokit ;
20+ using NLog ;
2021
2122namespace GitHub . ViewModels
2223{
@@ -25,6 +26,8 @@ namespace GitHub.ViewModels
2526 [ SuppressMessage ( "Microsoft.Design" , "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable" ) ]
2627 public class PullRequestCreationViewModel : BaseViewModel , IPullRequestCreationViewModel
2728 {
29+ static readonly Logger log = LogManager . GetCurrentClassLogger ( ) ;
30+
2831 readonly IRepositoryHost repositoryHost ;
2932 readonly ISimpleRepositoryModel activeRepo ;
3033 readonly Subject < Unit > initializationComplete = new Subject < Unit > ( ) ;
@@ -36,7 +39,7 @@ public class PullRequestCreationViewModel : BaseViewModel, IPullRequestCreationV
3639 IPullRequestService service , INotificationService notifications )
3740 : this ( connectionRepositoryHostMap . CurrentRepositoryHost , teservice . ActiveRepo , service , notifications )
3841 { }
39-
42+
4043 public PullRequestCreationViewModel ( IRepositoryHost repositoryHost , ISimpleRepositoryModel activeRepo ,
4144 IPullRequestService service , INotificationService notifications )
4245 {
@@ -78,18 +81,18 @@ public PullRequestCreationViewModel(IRepositoryHost repositoryHost, ISimpleRepos
7881 . Subscribe ( x => notifications . ShowError ( BranchValidator . ValidationResult . Message ) ) ;
7982
8083 createPullRequest = ReactiveCommand . CreateAsyncObservable ( whenAnyValidationResultChanges ,
81- _ => service . CreatePullRequest ( repositoryHost , activeRepo , PRTitle , Description , SourceBranch , TargetBranch )
82- ) ;
83- createPullRequest . ThrownExceptions . Subscribe ( ex =>
84- {
85- if ( ! ex . IsCriticalException ( ) )
86- {
87- //TODO:Will need a uniform solution to HTTP exception message handling
88- var apiException = ex as ApiValidationException ;
89- var error = apiException ? . ApiError ? . Errors ? . FirstOrDefault ( ) ;
90- notifications . ShowError ( error ? . Message ?? ex . Message ) ;
91- }
92- } ) ;
84+ _ => service
85+ . CreatePullRequest ( repositoryHost , activeRepo , PRTitle , Description ?? String . Empty , SourceBranch , TargetBranch )
86+ . Catch < IPullRequestModel , Exception > ( ex =>
87+ {
88+ log . Error ( ex ) ;
89+
90+ //TODO:Will need a uniform solution to HTTP exception message handling
91+ var apiException = ex as ApiValidationException ;
92+ var error = apiException ? . ApiError ? . Errors ? . FirstOrDefault ( ) ;
93+ notifications . ShowError ( error ? . Message ?? ex . Message ) ;
94+ return Observable . Empty < IPullRequestModel > ( ) ;
95+ } ) ) ;
9396 }
9497
9598 public override void Initialize ( [ AllowNull ] ViewWithData data )
0 commit comments