@@ -401,6 +401,94 @@ it("AwsJson10InvalidGreetingError:Error:GreetingWithErrors", async () => {
401401 fail ( "Expected an exception to be thrown from response" ) ;
402402} ) ;
403403
404+ /**
405+ * Parses a complex error with no message member
406+ */
407+ it ( "AwsJson10ComplexError:Error:GreetingWithErrors" , async ( ) => {
408+ const client = new JSONRPC10Client ( {
409+ ...clientParams ,
410+ requestHandler : new ResponseDeserializationTestHandler (
411+ false ,
412+ 400 ,
413+ {
414+ "content-type" : "application/x-amz-json-1.0" ,
415+ } ,
416+ `{
417+ "__type": "aws.protocoltests.json10#ComplexError",
418+ "TopLevel": "Top level",
419+ "Nested": {
420+ "Foo": "bar"
421+ }
422+ }`
423+ ) ,
424+ } ) ;
425+
426+ const params : any = { } ;
427+ const command = new GreetingWithErrorsCommand ( params ) ;
428+
429+ try {
430+ await client . send ( command ) ;
431+ } catch ( err ) {
432+ if ( err . name !== "ComplexError" ) {
433+ console . log ( err ) ;
434+ fail ( `Expected a ComplexError to be thrown, got ${ err . name } instead` ) ;
435+ return ;
436+ }
437+ const r : any = err ;
438+ expect ( r [ "$metadata" ] . httpStatusCode ) . toBe ( 400 ) ;
439+ const paramsToValidate : any = [
440+ {
441+ TopLevel : "Top level" ,
442+ Nested : {
443+ Foo : "bar" ,
444+ } ,
445+ } ,
446+ ] [ 0 ] ;
447+ Object . keys ( paramsToValidate ) . forEach ( ( param ) => {
448+ expect ( r [ param ] ) . toBeDefined ( ) ;
449+ expect ( equivalentContents ( paramsToValidate [ param ] , r [ param ] ) ) . toBe ( true ) ;
450+ } ) ;
451+ return ;
452+ }
453+ fail ( "Expected an exception to be thrown from response" ) ;
454+ } ) ;
455+
456+ /**
457+ * Parses a complex error with an empty body
458+ */
459+ it ( "AwsJson10EmptyComplexError:Error:GreetingWithErrors" , async ( ) => {
460+ const client = new JSONRPC10Client ( {
461+ ...clientParams ,
462+ requestHandler : new ResponseDeserializationTestHandler (
463+ false ,
464+ 400 ,
465+ {
466+ "content-type" : "application/x-amz-json-1.0" ,
467+ } ,
468+ `{
469+ "__type": "aws.protocoltests.json10#ComplexError"
470+ }`
471+ ) ,
472+ } ) ;
473+
474+ const params : any = { } ;
475+ const command = new GreetingWithErrorsCommand ( params ) ;
476+
477+ try {
478+ await client . send ( command ) ;
479+ } catch ( err ) {
480+ if ( err . name !== "ComplexError" ) {
481+ console . log ( err ) ;
482+ fail ( `Expected a ComplexError to be thrown, got ${ err . name } instead` ) ;
483+ return ;
484+ }
485+ const r : any = err ;
486+ expect ( r [ "$metadata" ] . httpStatusCode ) . toBe ( 400 ) ;
487+ return ;
488+ }
489+ fail ( "Expected an exception to be thrown from response" ) ;
490+ } ) ;
491+
404492/**
405493 * Serializes the X-Amzn-ErrorType header. For an example service, see Amazon EKS.
406494 */
@@ -710,94 +798,6 @@ it("AwsJson10FooErrorWithDunderTypeUriAndNamespace:Error:GreetingWithErrors", as
710798 fail ( "Expected an exception to be thrown from response" ) ;
711799} ) ;
712800
713- /**
714- * Parses a complex error with no message member
715- */
716- it ( "AwsJson10ComplexError:Error:GreetingWithErrors" , async ( ) => {
717- const client = new JSONRPC10Client ( {
718- ...clientParams ,
719- requestHandler : new ResponseDeserializationTestHandler (
720- false ,
721- 400 ,
722- {
723- "content-type" : "application/x-amz-json-1.0" ,
724- } ,
725- `{
726- "__type": "aws.protocoltests.json10#ComplexError",
727- "TopLevel": "Top level",
728- "Nested": {
729- "Foo": "bar"
730- }
731- }`
732- ) ,
733- } ) ;
734-
735- const params : any = { } ;
736- const command = new GreetingWithErrorsCommand ( params ) ;
737-
738- try {
739- await client . send ( command ) ;
740- } catch ( err ) {
741- if ( err . name !== "ComplexError" ) {
742- console . log ( err ) ;
743- fail ( `Expected a ComplexError to be thrown, got ${ err . name } instead` ) ;
744- return ;
745- }
746- const r : any = err ;
747- expect ( r [ "$metadata" ] . httpStatusCode ) . toBe ( 400 ) ;
748- const paramsToValidate : any = [
749- {
750- TopLevel : "Top level" ,
751- Nested : {
752- Foo : "bar" ,
753- } ,
754- } ,
755- ] [ 0 ] ;
756- Object . keys ( paramsToValidate ) . forEach ( ( param ) => {
757- expect ( r [ param ] ) . toBeDefined ( ) ;
758- expect ( equivalentContents ( paramsToValidate [ param ] , r [ param ] ) ) . toBe ( true ) ;
759- } ) ;
760- return ;
761- }
762- fail ( "Expected an exception to be thrown from response" ) ;
763- } ) ;
764-
765- /**
766- * Parses a complex error with an empty body
767- */
768- it ( "AwsJson10EmptyComplexError:Error:GreetingWithErrors" , async ( ) => {
769- const client = new JSONRPC10Client ( {
770- ...clientParams ,
771- requestHandler : new ResponseDeserializationTestHandler (
772- false ,
773- 400 ,
774- {
775- "content-type" : "application/x-amz-json-1.0" ,
776- } ,
777- `{
778- "__type": "aws.protocoltests.json10#ComplexError"
779- }`
780- ) ,
781- } ) ;
782-
783- const params : any = { } ;
784- const command = new GreetingWithErrorsCommand ( params ) ;
785-
786- try {
787- await client . send ( command ) ;
788- } catch ( err ) {
789- if ( err . name !== "ComplexError" ) {
790- console . log ( err ) ;
791- fail ( `Expected a ComplexError to be thrown, got ${ err . name } instead` ) ;
792- return ;
793- }
794- const r : any = err ;
795- expect ( r [ "$metadata" ] . httpStatusCode ) . toBe ( 400 ) ;
796- return ;
797- }
798- fail ( "Expected an exception to be thrown from response" ) ;
799- } ) ;
800-
801801/**
802802 * Custom endpoints supplied by users can have paths
803803 */
0 commit comments