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

Method fetch

packages/service-worker/worker/testing/mock.ts:148–176  ·  view source on GitHub ↗
(req: Request)

Source from the content-addressed store, hash-verified

146 }
147
148 async fetch(req: Request): Promise<Response> {
149 this.resolveNextRequest?.(req);
150 ({promise: this.nextRequest, resolve: this.resolveNextRequest} =
151 Promise.withResolvers<Request>());
152
153 await this.gate;
154
155 if (!this.online) {
156 throw new Error('Offline.');
157 }
158
159 this.requests.push(req);
160
161 if (req.credentials === 'include' || req.mode === 'no-cors') {
162 return new MockResponse(null, {status: 0, statusText: '', type: 'opaque'});
163 }
164 const url = req.url.split('?')[0];
165 if (this.resources.has(url)) {
166 const response = this.resources.get(url)!.clone();
167 if (response.redirected && req.redirect === 'error') {
168 throw new Error('Redirect disallowed by request policy.');
169 }
170 return response;
171 }
172 if (this.errors.has(url)) {
173 throw new Error('Intentional failure!');
174 }
175 return new MockResponse(null, {status: 404, statusText: 'Not Found'});
176 }
177
178 pause(): void {
179 ({promise: this.gate, resolve: this.resolve} = Promise.withResolvers<void>());

Callers 8

handleClickMethod · 0.45
safeFetchMethod · 0.45
safeFetchMethod · 0.45
safeFetchFunction · 0.45
handleFetchMethod · 0.45
resource_spec.tsFile · 0.45
FetchBackendClass · 0.45

Calls 5

withResolversMethod · 0.65
hasMethod · 0.65
cloneMethod · 0.65
getMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected