import StandardHttpClient from 'standard-http-client/src/standard-http-client.js'
Constructor Summary
Public Constructor | ||
public |
constructor(config: AxiosRequestConfig) |
Member Summary
Public Members | ||
public |
agent: AxiosInstance |
Method Summary
Public Methods | ||
public abstract |
afterSend(responseOrError: AxiosResponse | AxiosError) 请求完成之后统一要做的事情 |
|
public abstract |
beforeSend(config: AxiosRequestConfig) 发送请求之前统一要做的事情 |
|
public abstract |
handleError(error: AxiosError) 请求出错之后如何处理错误 |
|
public |
发送请求 |
|
public |
使用拦截器 |
Private Methods | ||
private |
_adapterDataOption(扩展的: AxiosRequestConfig) 将 config._data 适配为 config.params 和 config.data |
|
private |
_descClientError(error: Error) 描述客户端错误 |
|
private |
通过拦截器描述请求的错误信息 |
|
private |
_dispatchRequest(config: AxiosRequestConfig): Promise Dispatch a request to the server. |
|
private |
通过拦截器处理请求的错误 |
|
private |
_hook() 通过拦截器增加发送请求的 hook |
|
private |
_isApiSuccess(response: AxiosResponse): boolean 判断接口调用是否成功 |
|
private |
通过拦截器判断接口调用是否成功 |
|
private |
通过 JSONP 发送请求 |
|
private |
通过拦截器输出请求的错误日志 |
Public Constructors
public constructor(config: AxiosRequestConfig) source
Params:
Name | Type | Attribute | Description |
config | AxiosRequestConfig |
Public Members
public agent: AxiosInstance source
Public Methods
public abstract afterSend(responseOrError: AxiosResponse | AxiosError) source
请求完成之后统一要做的事情
Params:
Name | Type | Attribute | Description |
responseOrError | AxiosResponse | AxiosError |
public abstract beforeSend(config: AxiosRequestConfig) source
发送请求之前统一要做的事情
Params:
Name | Type | Attribute | Description |
config | AxiosRequestConfig |
public abstract handleError(error: AxiosError) source
请求出错之后如何处理错误
Params:
Name | Type | Attribute | Description |
error | AxiosError |
public send(config: AxiosRequestConfig): Promise source
发送请求
Params:
Name | Type | Attribute | Description |
config | AxiosRequestConfig |
|
扩展的 AxiosRequestConfig |
config._data | object |
|
实现类似 jQuery.ajax 的 data 配置项机制 |
config._jsonp | boolean |
|
是否通过 JSONP 来发送请求(注意此时 config 仅支持 baseURL, url, params, timeout, transformResponse 参数) |
config._jsonpCallback | string |
|
name of the query string parameter to specify the callback(defaults to |
Private Methods
private _adapterDataOption(扩展的: AxiosRequestConfig) source
将 config._data 适配为 config.params 和 config.data
当为 post/put/patch 请求时会将 config._data 转成 URL 编码的字符串
Params:
Name | Type | Attribute | Description |
扩展的 | AxiosRequestConfig | AxiosRequestConfig |
|
config._data | object | 实现类似 jQuery.ajax 的 data 配置项机制 |
private _descClientError(error: Error) source
描述客户端错误
Params:
Name | Type | Attribute | Description |
error | Error |
private _dispatchRequest(config: AxiosRequestConfig): Promise source
Dispatch a request to the server.
Params:
Name | Type | Attribute | Description |
config | AxiosRequestConfig |
private _hook() source
通过拦截器增加发送请求的 hook
┌─> 成功 ─> afterSend
beforeSend ─> send ─┤
└─> 失败 ─> afterSend
private _isApiSuccess(response: AxiosResponse): boolean source
判断接口调用是否成功
Params:
Name | Type | Attribute | Description |
response | AxiosResponse |