77using System . IO ;
88using MorphCmd . Models ;
99using Morph . Server . Sdk . Exceptions ;
10+ using System . Security . Authentication ;
1011
1112namespace MorphCmd
1213{
@@ -20,7 +21,7 @@ static void Main(string[] args)
2021 var output = new ConsoleOutput ( ) ;
2122 try
2223 {
23-
24+
2425 if ( args . Length < 2 )
2526 {
2627 RunUsageSamples . WriteCreds ( output ) ;
@@ -41,49 +42,51 @@ static void Main(string[] args)
4142
4243 catch ( AggregateException agr )
4344 {
44- foreach ( var e in agr . InnerExceptions )
45+ foreach ( var e in agr . Flatten ( ) . InnerExceptions )
4546 {
46- output . WriteError ( e . Message ) ;
47- if ( e is ResponseParseException rpe )
48- {
49- output . WriteError ( rpe . ServerResponseString ) ;
50- }
51- Exception inner = e . InnerException ;
52- if ( inner != null )
53- {
54- while ( inner . InnerException != null )
55- {
56- output . WriteError ( inner . Message ) ;
57- inner = inner . InnerException ;
58- }
59- }
47+ TraverseExceptionTree ( output , e ) ;
6048 }
6149 Environment . Exit ( 1 ) ;
6250
6351 }
6452 catch ( Exception ex )
6553 {
66- output . WriteError ( ex . Message ) ;
67- Exception inner = ex . InnerException ;
68- if ( inner != null )
69- {
70- while ( inner . InnerException != null )
71- {
72- output . WriteError ( inner . Message ) ;
73- inner = inner . InnerException ;
74- }
75- }
76-
77-
54+ TraverseExceptionTree ( output , ex ) ;
55+
7856 Environment . Exit ( 1 ) ;
7957 }
8058 }
8159
60+ private static void TraverseExceptionTree ( ConsoleOutput output , Exception e )
61+ {
62+ ProcessException ( e , output ) ;
63+ Exception inner = e . InnerException ;
64+ while ( inner != null )
65+ {
66+ ProcessException ( inner , output ) ;
67+ inner = inner . InnerException ;
68+ }
69+
70+ }
71+
72+ static void ProcessException ( Exception e , ConsoleOutput consoleOutput )
73+ {
74+ consoleOutput . WriteError ( e . Message ) ;
75+ if ( e is ResponseParseException rpe )
76+ {
77+ consoleOutput . WriteError ( rpe . ServerResponseString ) ;
78+ }
79+ if ( e is System . Security . Authentication . AuthenticationException )
80+ {
81+ consoleOutput . WriteInfo ( "To prevent this error use a valid ssl certificate." ) ;
82+ consoleOutput . WriteInfo ( "To suppress this error use /suppress-ssl-errors parameter." ) ;
83+ }
84+ }
8285
8386
8487 static async Task MainAsync ( Parameters parameters )
8588 {
86-
89+ NetworkUtil . ConfigureServicePointManager ( parameters . SuppressSslErrors ) ;
8790 var apiClient = new MorphServerApiClient ( parameters . Host ) ;
8891 var output = new ConsoleOutput ( ) ;
8992 var input = new ConsoleInput ( ) ;
0 commit comments