MCPcopy Index your code
hub / github.com/angular/angular / flush

Method flush

packages/common/http/testing/src/request.ts:63–105  ·  view source on GitHub ↗

* Resolve the request by returning a body plus additional HTTP information (such as response * headers) if provided. * If the request specifies an expected body type, the body is converted into the requested type. * Otherwise, the body is converted to `JSON` by default. * * Both succe

(
    body:
      | ArrayBuffer
      | Blob
      | boolean
      | string
      | number
      | Object
      | (boolean | string | number | Object | null)[]
      | null,
    opts: {
      headers?: HttpHeaders | {[name: string]: string | string[]};
      status?: number;
      statusText?: string;
    } = {},
  )

Source from the content-addressed store, hash-verified

61 * Both successful and unsuccessful responses can be delivered via `flush()`.
62 */
63 flush(
64 body:
65 | ArrayBuffer
66 | Blob
67 | boolean
68 | string
69 | number
70 | Object
71 | (boolean | string | number | Object | null)[]
72 | null,
73 opts: {
74 headers?: HttpHeaders | {[name: string]: string | string[]};
75 status?: number;
76 statusText?: string;
77 } = {},
78 ): void {
79 if (this.cancelled) {
80 throw new Error(`Cannot flush a cancelled request.`);
81 }
82 const url = this.request.urlWithParams;
83 const headers =
84 opts.headers instanceof HttpHeaders ? opts.headers : new HttpHeaders(opts.headers);
85 body = _maybeConvertBody(this.request.responseType, body);
86 let statusText: string | undefined = opts.statusText;
87 let status: number = opts.status !== undefined ? opts.status : HttpStatusCode.Ok;
88 if (opts.status === undefined) {
89 if (body === null) {
90 status = HttpStatusCode.NoContent;
91 statusText ||= 'No Content';
92 } else {
93 statusText ||= 'OK';
94 }
95 }
96 if (statusText === undefined) {
97 throw new Error('statusText is required when setting a custom status.');
98 }
99 if (status >= 200 && status < 300) {
100 this.observer.next(new HttpResponse<any>({body, headers, status, statusText, url}));
101 this.observer.complete();
102 } else {
103 this.observer.error(new HttpErrorResponse({error: body, headers, status, statusText, url}));
104 }
105 }
106
107 /**
108 * Resolve the request by returning an `ErrorEvent` (e.g. simulating a network failure).

Callers 10

resource.spec.tsFile · 0.45
provider_spec.tsFile · 0.45
client_spec.tsFile · 0.45
module_spec.tsFile · 0.45
makeRequestAndExpectOneFunction · 0.45
xsrf_spec.tsFile · 0.45
resource_spec.tsFile · 0.45
request_spec.tsFile · 0.45

Calls 4

_maybeConvertBodyFunction · 0.85
errorMethod · 0.65
nextMethod · 0.45
completeMethod · 0.45

Tested by

no test coverage detected