@@ -118,6 +118,29 @@ describe('grpc-web generated code: promise-based client', function() {
118118 } ) ;
119119 } ) ;
120120
121+ it ( 'should receive error, on http error - Content-Type not matching application/grpc*' , function ( done ) {
122+ const { EchoServicePromiseClient} = require ( genCodePath ) ;
123+ const { EchoRequest} = require ( protoGenCodePath ) ;
124+ MockXMLHttpRequest . onSend = function ( xhr ) {
125+ xhr . respond (
126+ 505 , { 'Content-Type' : 'text/html' } ) ;
127+ } ;
128+ var echoService = new EchoServicePromiseClient ( 'MyHostname' , null , null ) ;
129+ var request = new EchoRequest ( ) ;
130+ request . setMessage ( 'aaa' ) ;
131+
132+ echoService . echo ( request , { } )
133+ . then ( ( response ) => {
134+ assert . fail ( 'should not receive response' ) ;
135+ } )
136+ . catch ( ( error ) => {
137+ assert ( 'metadata' in error ) ;
138+ assert ( 'httpStatusCode' in error . metadata ) ;
139+ assert . equal ( 505 , error . metadata . httpStatusCode ) ;
140+ done ( ) ;
141+ } ) ;
142+ } ) ;
143+
121144 it ( 'should receive error' , function ( done ) {
122145 const { EchoServicePromiseClient} = require ( genCodePath ) ;
123146 const { EchoRequest} = require ( protoGenCodePath ) ;
@@ -613,6 +636,36 @@ describe('grpc-web generated code: callbacks tests', function() {
613636 } ) ;
614637 } ) ;
615638
639+ it ( 'should receive error, on http error - Content-Type not matching application/grpc*' , function ( done ) {
640+ done = multiDone ( done , 2 ) ;
641+ MockXMLHttpRequest . onSend = function ( xhr ) {
642+ xhr . respond (
643+ 505 , { 'Content-Type' : 'text/html' } ) ;
644+ } ;
645+ var call = echoService . echo (
646+ request , { } ,
647+ function ( err , response ) {
648+ if ( response ) {
649+ assert . fail ( 'should not have received response with non-OK status' ) ;
650+ } else {
651+ assert ( 'metadata' in err ) ;
652+ assert ( 'httpStatusCode' in err . metadata ) ;
653+ assert . equal ( 505 , err . metadata . httpStatusCode ) ;
654+ }
655+ done ( ) ;
656+ }
657+ ) ;
658+ call . on ( 'status' , ( status ) => {
659+ assert ( 'metadata' in status ) ;
660+ assert ( 'httpStatusCode' in status . metadata ) ;
661+ assert . equal ( 505 , status . metadata . httpStatusCode ) ;
662+ done ( ) ;
663+ } ) ;
664+ call . on ( 'error' , ( error ) => {
665+ assert . fail ( 'error callback should not be called for unary calls' ) ;
666+ } ) ;
667+ } ) ;
668+
616669 it ( 'should receive error, on http error' , function ( done ) {
617670 done = multiDone ( done , 2 ) ;
618671 MockXMLHttpRequest . onSend = function ( xhr ) {
@@ -802,6 +855,30 @@ describe('grpc-web generated code: callbacks tests', function() {
802855 } ) ;
803856 } ) ;
804857
858+ it ( 'should receive error, on http error (streaming) - Content-Type not matching application/grpc*' , function ( done ) {
859+ done = multiDone ( done , 2 ) ;
860+ MockXMLHttpRequest . onSend = function ( xhr ) {
861+ xhr . respond (
862+ 505 , { 'Content-Type' : 'text/html' } ) ;
863+ } ;
864+ var call = echoService . serverStreamingEcho ( request , { } ) ;
865+ call . on ( 'data' , ( response ) => {
866+ assert . fail ( 'should not receive data response' ) ;
867+ } ) ;
868+ call . on ( 'status' , ( status ) => {
869+ assert ( 'metadata' in status ) ;
870+ assert ( 'httpStatusCode' in status . metadata ) ;
871+ assert . equal ( 505 , status . metadata . httpStatusCode ) ;
872+ done ( ) ;
873+ } ) ;
874+ call . on ( 'error' , ( error ) => {
875+ assert ( 'metadata' in error ) ;
876+ assert ( 'httpStatusCode' in error . metadata ) ;
877+ assert . equal ( 505 , error . metadata . httpStatusCode ) ;
878+ done ( ) ;
879+ } ) ;
880+ } ) ;
881+
805882 it ( 'should receive error, on http error (streaming)' , function ( done ) {
806883 done = multiDone ( done , 2 ) ;
807884 MockXMLHttpRequest . onSend = function ( xhr ) {
0 commit comments