MCPcopy
hub / github.com/angular/angular / fetch

Method fetch

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

Source from the content-addressed store, hash-verified

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

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 4

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

Tested by

no test coverage detected