docs(API): 翻译完了 HttpResponse

This commit is contained in:
Zhicheng Wang 2018-09-04 16:37:03 +08:00
parent 2a1fbec879
commit d9a50a8452
2 changed files with 77 additions and 1 deletions

View File

@ -77,7 +77,7 @@
[x] | common/formatDate | 0.21
[x] | core/ComponentFactoryResolver | 0.20
[x] | forms/Form | 0.20
[ ] | common/http/HttpErrorResponse | 0.20
[x] | common/http/HttpErrorResponse | 0.20
[ ] | core/QueryList | 0.19
[ ] | forms | 0.19
[ ] | animations/state | 0.19

View File

@ -11,36 +11,49 @@ import {HttpHeaders} from './headers';
/**
* Type enumeration for the different kinds of `HttpEvent`.
*
* `HttpEvent`
*
*/
export enum HttpEventType {
/**
* The request was sent out over the wire.
*
* 线
*/
Sent,
/**
* An upload progress event was received.
*
*
*/
UploadProgress,
/**
* The response status code and headers were received.
*
*
*/
ResponseHeader,
/**
* A download progress event was received.
*
*
*/
DownloadProgress,
/**
* The full response including the body was received.
*
*
*/
Response,
/**
* A custom event from an interceptor or a backend.
*
*
*/
User,
}
@ -49,21 +62,28 @@ export enum HttpEventType {
* Base interface for progress events.
*
*
*
*/
export interface HttpProgressEvent {
/**
* Progress event type is either upload or download.
*
*
*/
type: HttpEventType.DownloadProgress|HttpEventType.UploadProgress;
/**
* Number of bytes uploaded or downloaded.
*
*
*/
loaded: number;
/**
* Total number of bytes to upload or download. Depending on the request or
* response, this may not be computable and thus may not be present.
*
*
*/
total?: number;
}
@ -71,6 +91,7 @@ export interface HttpProgressEvent {
/**
* A download progress event.
*
*
*
*/
export interface HttpDownloadProgressEvent extends HttpProgressEvent {
@ -79,7 +100,11 @@ export interface HttpDownloadProgressEvent extends HttpProgressEvent {
/**
* The partial response body as downloaded so far.
*
*
*
* Only present if the responseType was `text`.
*
* responseType `text`
*/
partialText?: string;
}
@ -87,6 +112,7 @@ export interface HttpDownloadProgressEvent extends HttpProgressEvent {
/**
* An upload progress event.
*
*
*
*/
export interface HttpUploadProgressEvent extends HttpProgressEvent {
@ -98,6 +124,8 @@ export interface HttpUploadProgressEvent extends HttpProgressEvent {
* when a request may be retried multiple times, to distinguish between
* retries on the final event stream.
*
*
*
*
*/
export interface HttpSentEvent { type: HttpEventType.Sent; }
@ -105,9 +133,12 @@ export interface HttpSentEvent { type: HttpEventType.Sent; }
/**
* A user-defined event.
*
*
*
* Grouping all custom events under this type ensures they will be handled
* and forwarded by all implementations of interceptors.
*
*
*
*/
export interface HttpUserEvent<T> { type: HttpEventType.User; }
@ -116,8 +147,11 @@ export interface HttpUserEvent<T> { type: HttpEventType.User; }
* An error that represents a failed attempt to JSON.parse text coming back
* from the server.
*
* JSON.parse
*
* It bundles the Error object with the actual response body that failed to parse.
*
* `Error`
*
*/
export interface HttpJsonParseError {
@ -128,8 +162,11 @@ export interface HttpJsonParseError {
/**
* Union type for all possible events on the response stream.
*
*
*
* Typed according to the expected type of the response.
*
*
*
*/
export type HttpEvent<T> =
@ -138,38 +175,53 @@ export type HttpEvent<T> =
/**
* Base class for both `HttpResponse` and `HttpHeaderResponse`.
*
* `HttpResponse` `HttpHeaderResponse`
*
*/
export abstract class HttpResponseBase {
/**
* All response headers.
*
*
*/
readonly headers: HttpHeaders;
/**
* Response status code.
*
*
*/
readonly status: number;
/**
* Textual description of response status code.
*
*
*
* Do not depend on this.
*
*
*/
readonly statusText: string;
/**
* URL of the resource retrieved, or null if not available.
*
* URL `null`
*/
readonly url: string|null;
/**
* Whether the status code falls in the 2xx range.
*
* 2xx
*/
readonly ok: boolean;
/**
* Type of the response, narrowed to either the full response or the header.
*
*
*/
// TODO(issue/24571): remove '!'.
readonly type !: HttpEventType.Response | HttpEventType.ResponseHeader;
@ -177,8 +229,12 @@ export abstract class HttpResponseBase {
/**
* Super-constructor for all responses.
*
* super
*
* The single parameter accepted is an initialization hash. Any properties
* of the response passed there will override the default values.
*
*
*/
constructor(
init: {
@ -204,14 +260,19 @@ export abstract class HttpResponseBase {
* A partial HTTP response which only includes the status and header data,
* but no response body.
*
* HTTP
*
* `HttpHeaderResponse` is a `HttpEvent` available on the response
* event stream, only when progress events are requested.
*
* `HttpHeaderResponse` `HttpEvent`
*
*/
export class HttpHeaderResponse extends HttpResponseBase {
/**
* Create a new `HttpHeaderResponse` with the given parameters.
*
* `HttpHeaderResponse`
*/
constructor(init: {
headers?: HttpHeaders,
@ -227,6 +288,8 @@ export class HttpHeaderResponse extends HttpResponseBase {
/**
* Copy this `HttpHeaderResponse`, overriding its contents with the
* given parameter hash.
*
* `HttpHeaderResponse`使
*/
clone(update: {headers?: HttpHeaders; status?: number; statusText?: string; url?: string;} = {}):
HttpHeaderResponse {
@ -245,19 +308,26 @@ export class HttpHeaderResponse extends HttpResponseBase {
* A full HTTP response, including a typed response body (which may be `null`
* if one was not returned).
*
* HTTP `null`
*
* `HttpResponse` is a `HttpEvent` available on the response event
* stream.
*
*
* `HttpResponse` `HttpEvent`
*/
export class HttpResponse<T> extends HttpResponseBase {
/**
* The response body, or `null` if one was not returned.
*
* `null`
*/
readonly body: T|null;
/**
* Construct a new `HttpResponse`.
*
* `HttpResponse`
*/
constructor(init: {
body?: T | null, headers?: HttpHeaders; status?: number; statusText?: string; url?: string;
@ -292,6 +362,8 @@ export class HttpResponse<T> extends HttpResponseBase {
* non-successful HTTP status, an error while executing the request,
* or some other failure which occurred during the parsing of the response.
*
* HTTP
*
* Any error returned on the `Observable` response stream will be
* wrapped in an `HttpErrorResponse` to provide additional context about
* the state of the HTTP layer when the error occurred. The error property
@ -299,6 +371,8 @@ export class HttpResponse<T> extends HttpResponseBase {
* from the server.
*
*
* `Observable` `HttpErrorResponse` 便 HTTP
*
*/
export class HttpErrorResponse extends HttpResponseBase implements Error {
readonly name = 'HttpErrorResponse';
@ -307,6 +381,8 @@ export class HttpErrorResponse extends HttpResponseBase implements Error {
/**
* Errors are never okay, even when the status code is in the 2xx success range.
*
* `ok` `false` HTTP 2xx
*/
readonly ok = false;