17
17
using System . Reactive ;
18
18
using System . Diagnostics . CodeAnalysis ;
19
19
using Octokit ;
20
+ using NLog ;
20
21
21
22
namespace GitHub . ViewModels
22
23
{
@@ -25,6 +26,8 @@ namespace GitHub.ViewModels
25
26
[ SuppressMessage ( "Microsoft.Design" , "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable" ) ]
26
27
public class PullRequestCreationViewModel : BaseViewModel , IPullRequestCreationViewModel
27
28
{
29
+ static readonly Logger log = LogManager . GetCurrentClassLogger ( ) ;
30
+
28
31
readonly IRepositoryHost repositoryHost ;
29
32
readonly ISimpleRepositoryModel activeRepo ;
30
33
readonly Subject < Unit > initializationComplete = new Subject < Unit > ( ) ;
@@ -36,7 +39,7 @@ public class PullRequestCreationViewModel : BaseViewModel, IPullRequestCreationV
36
39
IPullRequestService service , INotificationService notifications )
37
40
: this ( connectionRepositoryHostMap . CurrentRepositoryHost , teservice . ActiveRepo , service , notifications )
38
41
{ }
39
-
42
+
40
43
public PullRequestCreationViewModel ( IRepositoryHost repositoryHost , ISimpleRepositoryModel activeRepo ,
41
44
IPullRequestService service , INotificationService notifications )
42
45
{
@@ -78,18 +81,18 @@ public PullRequestCreationViewModel(IRepositoryHost repositoryHost, ISimpleRepos
78
81
. Subscribe ( x => notifications . ShowError ( BranchValidator . ValidationResult . Message ) ) ;
79
82
80
83
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
+ } ) ) ;
93
96
}
94
97
95
98
public override void Initialize ( [ AllowNull ] ViewWithData data )
0 commit comments