@@ -489,36 +489,16 @@ private TemplateValidationInfo GetTemplateValidationResult(PSDeploymentCmdletPar
489
489
try
490
490
{
491
491
var validationResult = this . ValidateDeployment ( parameters , deployment ) ;
492
- switch ( validationResult )
493
- {
494
- case DeploymentExtended deploymentExtended :
495
- return new TemplateValidationInfo ( deploymentExtended . Properties ? . Providers ? . ToList ( ) ?? new List < Provider > ( ) , new List < ErrorDetail > ( ) , deploymentExtended . Properties ? . Diagnostics ? . ToList ( ) ?? new List < DeploymentDiagnosticsDefinition > ( ) ) ;
496
- case DeploymentValidationError deploymentValidationError :
497
- return new TemplateValidationInfo ( new List < Provider > ( ) , new List < ErrorDetail > ( deploymentValidationError . Error . AsArray ( ) ) , new List < DeploymentDiagnosticsDefinition > ( ) ) ;
498
- case JObject obj :
499
- // 202 Response is not deserialized in DeploymentsOperations so we should attempt to deserialize the object here before failing
500
- // Should attempt to deserialize for success(DeploymentExtended)
501
- try
502
- {
503
- var deploymentDeserialized = SafeJsonConvert . DeserializeObject < DeploymentExtended > ( validationResult . ToString ( ) , ResourceManagementClient . DeserializationSettings ) ;
504
- return new TemplateValidationInfo ( deploymentDeserialized ? . Properties ? . Providers ? . ToList ( ) ?? new List < Provider > ( ) , new List < ErrorDetail > ( ) , deploymentDeserialized ? . Properties ? . Diagnostics ? . ToList ( ) ?? new List < DeploymentDiagnosticsDefinition > ( ) ) ;
505
- }
506
- catch ( Newtonsoft . Json . JsonException )
507
- {
508
- throw new InvalidOperationException ( $ "Received unexpected type { validationResult . GetType ( ) } ") ;
509
- }
510
- default :
511
- throw new InvalidOperationException ( $ "Received unexpected type { validationResult . GetType ( ) } ") ;
512
- }
492
+ return new TemplateValidationInfo ( validationResult ) ;
513
493
}
514
494
catch ( Exception ex )
515
495
{
516
496
var error = HandleError ( ex ) . FirstOrDefault ( ) ;
517
- return new TemplateValidationInfo ( new List < Provider > ( ) , error . AsArray ( ) . ToList ( ) , new List < DeploymentDiagnosticsDefinition > ( ) ) ;
497
+ return new TemplateValidationInfo ( new DeploymentValidateResult ( error ) ) ;
518
498
}
519
499
}
520
500
521
- private object ValidateDeployment ( PSDeploymentCmdletParameters parameters , Deployment deployment )
501
+ private DeploymentValidateResult ValidateDeployment ( PSDeploymentCmdletParameters parameters , Deployment deployment )
522
502
{
523
503
var scopedDeployment = new ScopedDeployment { Properties = deployment . Properties , Location = deployment . Location } ;
524
504
@@ -547,26 +527,26 @@ private object ValidateDeployment(PSDeploymentCmdletParameters parameters, Deplo
547
527
}
548
528
}
549
529
550
- private List < ErrorDetail > HandleError ( Exception ex )
530
+ private List < ErrorResponse > HandleError ( Exception ex )
551
531
{
552
532
if ( ex == null )
553
533
{
554
534
return null ;
555
535
}
556
536
557
- ErrorDetail error = null ;
537
+ ErrorResponse error = null ;
558
538
var innerException = HandleError ( ex . InnerException ) ;
559
539
if ( ex is CloudException )
560
540
{
561
541
var cloudEx = ex as CloudException ;
562
- error = new ErrorDetail ( cloudEx . Body ? . Code , cloudEx . Body ? . Message , cloudEx . Body ? . Target , innerException ) ;
542
+ error = new ErrorResponse ( cloudEx . Body ? . Code , cloudEx . Body ? . Message , cloudEx . Body ? . Target , innerException ) ;
563
543
}
564
544
else
565
545
{
566
- error = new ErrorDetail ( null , ex . Message , null , innerException ) ;
546
+ error = new ErrorResponse ( null , ex . Message , null , innerException ) ;
567
547
}
568
548
569
- return new List < ErrorDetail > { error } ;
549
+ return new List < ErrorResponse > { error } ;
570
550
571
551
}
572
552
@@ -1529,7 +1509,7 @@ private DeploymentExtended ExecuteDeploymentInternal(PSDeploymentCmdletParameter
1529
1509
return ProvisionDeploymentStatus ( parameters , deployment ) ;
1530
1510
}
1531
1511
1532
- private void DisplayInnerDetailErrorMessage ( ErrorDetail error )
1512
+ private void DisplayInnerDetailErrorMessage ( ErrorResponse error )
1533
1513
{
1534
1514
WriteError ( string . Format ( ErrorFormat , error . Code , error . Message ) ) ;
1535
1515
if ( error . Details != null )
0 commit comments