@@ -13,6 +13,7 @@ import {
1313 inject ,
1414 Injectable ,
1515 runInInjectionContext ,
16+ ɵRuntimeError as RuntimeError ,
1617} from '@angular/core' ;
1718import { Observable , Observer } from 'rxjs' ;
1819
@@ -26,6 +27,7 @@ import {
2627 HttpEventType ,
2728 HttpResponse ,
2829} from './response' ;
30+ import { RuntimeErrorCode } from './errors' ;
2931
3032// Every request made through JSONP needs a callback name that's unique across the
3133// whole page. Each request is assigned an id and the callback name is constructed
@@ -115,15 +117,24 @@ export class JsonpClientBackend implements HttpBackend {
115117 // Firstly, check both the method and response type. If either doesn't match
116118 // then the request was improperly routed here and cannot be handled.
117119 if ( req . method !== 'JSONP' ) {
118- throw new Error ( JSONP_ERR_WRONG_METHOD ) ;
120+ throw new RuntimeError (
121+ RuntimeErrorCode . JSONP_WRONG_METHOD ,
122+ ngDevMode && JSONP_ERR_WRONG_METHOD ,
123+ ) ;
119124 } else if ( req . responseType !== 'json' ) {
120- throw new Error ( JSONP_ERR_WRONG_RESPONSE_TYPE ) ;
125+ throw new RuntimeError (
126+ RuntimeErrorCode . JSONP_WRONG_RESPONSE_TYPE ,
127+ ngDevMode && JSONP_ERR_WRONG_RESPONSE_TYPE ,
128+ ) ;
121129 }
122130
123131 // Check the request headers. JSONP doesn't support headers and
124132 // cannot set any that were supplied.
125133 if ( req . headers . keys ( ) . length > 0 ) {
126- throw new Error ( JSONP_ERR_HEADERS_NOT_SUPPORTED ) ;
134+ throw new RuntimeError (
135+ RuntimeErrorCode . JSONP_HEADERS_NOT_SUPPORTED ,
136+ ngDevMode && JSONP_ERR_HEADERS_NOT_SUPPORTED ,
137+ ) ;
127138 }
128139
129140 // Everything else happens inside the Observable boundary.
@@ -178,7 +189,7 @@ export class JsonpClientBackend implements HttpBackend {
178189 // if the JSONP script loads successfully. The event itself is unimportant.
179190 // If something went wrong, onLoad() may run without the response callback
180191 // having been invoked.
181- const onLoad = ( event : Event ) => {
192+ const onLoad = ( ) => {
182193 // We wrap it in an extra Promise, to ensure the microtask
183194 // is scheduled after the loaded endpoint has executed any potential microtask itself,
184195 // which is not guaranteed in Internet Explorer and EdgeHTML. See issue #39496
@@ -220,7 +231,7 @@ export class JsonpClientBackend implements HttpBackend {
220231 // onError() is the error callback, which runs if the script returned generates
221232 // a Javascript error. It emits the error via the Observable error channel as
222233 // a HttpErrorResponse.
223- const onError : any = ( error : Error ) => {
234+ const onError = ( error : Error ) => {
224235 cleanup ( ) ;
225236
226237 // Wrap the error in a HttpErrorResponse.
0 commit comments