MCPcopy Create free account
hub / github.com/angular/angular / onLoad

Method onLoad

packages/common/http/src/jsonp.ts:216–253  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

214 // If something went wrong, onLoad() may run without the response callback
215 // having been invoked.
216 const onLoad = () => {
217 // We wrap it in an extra Promise, to ensure the microtask
218 // is scheduled after the loaded endpoint has executed any potential microtask itself,
219 // which is not guaranteed in Internet Explorer and EdgeHTML. See issue #39496
220 this.resolvedPromise.then(() => {
221 // Cleanup the page.
222 cleanup();
223
224 // Check whether the response callback has run.
225 if (!finished) {
226 // It hasn't, something went wrong with the request. Return an error via
227 // the Observable error path. All JSONP errors have status 0.
228 observer.error(
229 new HttpErrorResponse({
230 url,
231 status: 0,
232 statusText: 'JSONP Error',
233 error: new Error(JSONP_ERR_NO_CALLBACK),
234 }),
235 );
236 return;
237 }
238
239 // Success. body either contains the response body or null if none was
240 // returned.
241 observer.next(
242 new HttpResponse({
243 body,
244 status: HTTP_STATUS_CODE_OK,
245 statusText: 'OK',
246 url,
247 }),
248 );
249
250 // Complete the stream, the response is over.
251 observer.complete();
252 });
253 };
254
255 // onError() is the error callback, which runs if the script returned generates
256 // a Javascript error. It emits the error via the Observable error channel as

Callers 1

Calls 5

thenMethod · 0.65
errorMethod · 0.65
cleanupFunction · 0.50
nextMethod · 0.45
completeMethod · 0.45

Tested by

no test coverage detected