@huaweicloud/huaweicloud-sdk-core
Advanced tools
Comparing version 3.0.9-beta to 3.0.10-beta
@@ -0,1 +1,61 @@ | ||
# 3.0.10-beta 2021-07-09 | ||
### HuaweiCloud SDK Core | ||
- _新增特性_ | ||
- 无 | ||
- _解决问题_ | ||
- 修复 Response 返回层级错误 | ||
- _特性变更_ | ||
- 优化异常信息 | ||
### HuaweiCloud SDK CCE | ||
- _新增特性_ | ||
- 支持接口`RemoveNode`、`MigrateNode` | ||
- _解决问题_ | ||
- 无 | ||
- _特性变更_ | ||
- 接口`DeleteCluster`新增请求参数`tobedeleted` | ||
### HuaweiCloud SDK EIP | ||
- _新增特性_ | ||
- 无 | ||
- _解决问题_ | ||
- 无 | ||
- _特性变更_ | ||
- 接口`CreateSharedBandwidth`、`ListBandwidths`新增响应参数`publicip_border_group` | ||
### HuaweiCloud SDK IMS | ||
- _新增特性_ | ||
- 无 | ||
- _解决问题_ | ||
- 无 | ||
- _特性变更_ | ||
- 接口`GlanceCreateImageMetadata`新增响应参数`__root_origin`、`checksum`、`size` | ||
- 接口`GlanceAddImageMember`移除请求参数`deleted`、`deleted_at`,新增以下请求参数: | ||
- `__lazyloading` | ||
- `__os_feature_list` | ||
- `__root_origin` | ||
- `__sequence_num` | ||
- `__support_agent_list` | ||
- `__system__cmkid` | ||
- `active_at` | ||
- `hw_vif_multiqueue_enabled` | ||
- `max_ram` | ||
- `__image_location` | ||
- `__is_config_init` | ||
- `__account_code` | ||
### HuaweiCloud SDK IoTDA | ||
- _新增特性_ | ||
- 无 | ||
- _解决问题_ | ||
- 无 | ||
- _特性变更_ | ||
- 接口`ListRules`新增响应参数`edge_node_ids`、`last_update_time` | ||
# 3.0.9-beta 2021-06-29 | ||
@@ -2,0 +62,0 @@ |
@@ -0,1 +1,60 @@ | ||
# 3.0.10-beta 2021-07-09 | ||
### HuaweiCloud SDK Core | ||
- _feature_ | ||
- None | ||
- _Bug Fix_ | ||
- The response level is incorrect. | ||
- _Change_ | ||
- Optimize exception information. | ||
### HuaweiCloud SDK CCE | ||
- _Features_ | ||
- Support the interfaces `RemoveNode`,`MigrateNode`. | ||
- _Bug Fix_ | ||
- None | ||
- _Change_ | ||
- Add the request parameter `tobedeleted` to the interface `DeleteCluster`. | ||
### HuaweiCloud SDK EIP | ||
- _Features_ | ||
- None | ||
- _Bug Fix_ | ||
- None | ||
- _Change_ | ||
- Add the response parameter `publicip_border_group` to the interfaces `CreateSharedBandwidth`,`ListBandwidths`. | ||
### HuaweiCloud SDK IMS | ||
- _Features_ | ||
- None | ||
- _Bug Fix_ | ||
- None | ||
- _Change_ | ||
- Add the response parameters `__root_origin`,`checksum`,`size` to the interfaces `GlanceCreateImageMetadata`. | ||
- Remove the request parameters `deleted`, `deleted_at` of the interface `GlanceAddImageMember`, and add the following request parameters: | ||
- `__lazyloading` | ||
- `__os_feature_list` | ||
- `__root_origin` | ||
- `__sequence_num` | ||
- `__support_agent_list` | ||
- `__system__cmkid` | ||
- `active_at` | ||
- `hw_vif_multiqueue_enabled` | ||
- `max_ram` | ||
- `__image_location` | ||
- `__is_config_init` | ||
- `__account_code` | ||
### HuaweiCloud SDK IoTDA | ||
- _Features_ | ||
- None | ||
- _Bug Fix_ | ||
- None | ||
- _Change_ | ||
- Add the response parameters `edge_node_ids`, `last_update_time` to the interface `ListRules`. | ||
# 3.0.9-beta 2021-06-29 | ||
@@ -2,0 +61,0 @@ |
@@ -0,10 +1,5 @@ | ||
import { ExceptionResponse } from "./ExceptionResponse"; | ||
import { ServiceResponseException } from "./ServiceResponseException"; | ||
export declare class ExceptionUtil { | ||
static generalException(httpStatusCode: string | number, errorData: { | ||
error_code: any; | ||
error_msg: any; | ||
request_id: any; | ||
code: any; | ||
message: any; | ||
} | null | undefined): ServiceResponseException; | ||
static generalException(exception: ExceptionResponse): ServiceResponseException; | ||
} |
@@ -30,18 +30,8 @@ "use strict"; | ||
} | ||
ExceptionUtil.generalException = function (httpStatusCode, errorData) { | ||
var errorCode; | ||
var errorMsg; | ||
var requestId; | ||
if (errorData !== null && errorData !== undefined) { | ||
errorCode = errorData.error_code; | ||
errorMsg = errorData.error_msg; | ||
requestId = errorData.request_id; | ||
if (errorCode === null || errorCode === undefined) { | ||
errorCode = errorData.code; | ||
errorMsg = errorData.message; | ||
if (errorCode === null || errorCode === undefined) { | ||
errorMsg = errorData; | ||
} | ||
} | ||
} | ||
ExceptionUtil.generalException = function (exception) { | ||
var data = exception.data || {}; | ||
var errorCode = data.error ? data.error.code : exception.status; | ||
var errorMsg = data.error ? data.error.message : exception.message; | ||
var requestId = exception.requestId; | ||
var httpStatusCode = exception.status; | ||
if (httpStatusCode) { | ||
@@ -48,0 +38,0 @@ if (httpStatusCode >= 400 && httpStatusCode < 500) { |
import { HttpClient } from "./http/HttpClient"; | ||
import { ICredential } from "./auth/ICredential"; | ||
import { SdkResponse } from "./SdkResponse"; | ||
export declare class HcClient { | ||
@@ -14,5 +15,5 @@ private httpClient; | ||
withHttpsAgent(proxyAgent: string): this; | ||
sendRequest<T>(options: any): Promise<T>; | ||
sendRequest<T extends SdkResponse>(options: any): Promise<T> | Promise<any>; | ||
private buildRequest; | ||
private extractResponse; | ||
} |
@@ -25,3 +25,2 @@ "use strict"; | ||
var IHttpRequestBuilder_1 = require("./http/IHttpRequestBuilder"); | ||
var SdkResponse_1 = require("./SdkResponse"); | ||
var ExceptionUtil_1 = require("./exception/ExceptionUtil"); | ||
@@ -57,5 +56,3 @@ var logger_1 = require("./logger"); | ||
}, function (err) { | ||
var error = err; | ||
var statusCode = error.status; | ||
return ExceptionUtil_1.ExceptionUtil.generalException(statusCode, error.body); | ||
return ExceptionUtil_1.ExceptionUtil.generalException(err); | ||
}); | ||
@@ -83,2 +80,3 @@ }; | ||
} | ||
httpRequest.proxy = this.proxyAgent; | ||
return httpRequest; | ||
@@ -91,8 +89,8 @@ }; | ||
if (contentType && contentType == 'application/octet-stream') { | ||
return result.result; | ||
return result.data; | ||
} | ||
else { | ||
var response = new SdkResponse_1.SdkResponse(); | ||
response.setStatusCode(result.status); | ||
response.setResult(result.result); | ||
var response = result.data instanceof Object ? result.data : {}; | ||
var sdkRespone = response; | ||
sdkRespone.httpStatusCode = result.statusCode; | ||
return response; | ||
@@ -99,0 +97,0 @@ } |
import { IHttpRequest } from './IHttpRequest'; | ||
import { HttpClient } from './HttpClient'; | ||
import { Logger, LogLevel } from '../logger'; | ||
import { DefaultHttpResponse } from './DefaultHttpResponse'; | ||
export declare class DefaultHttpClient implements HttpClient { | ||
@@ -10,17 +11,15 @@ private axiosInstance; | ||
private logger; | ||
private defaultOption; | ||
private DEFAULT_HEADERS; | ||
constructor({ proxy, logger, logLevel, headers }: ClientOptions); | ||
sendRequest(httpRequest: IHttpRequest): Promise<any>; | ||
constructor(options?: ClientOptions); | ||
private init; | ||
sendRequest<T = any>(httpRequest: IHttpRequest): Promise<DefaultHttpResponse<T>>; | ||
private _request; | ||
private _convertResponse; | ||
transformOptions(data: any, headers: any): any; | ||
/** | ||
* Format error returned by axios | ||
* @private | ||
* @returns {Error} | ||
* @param axiosError | ||
*/ | ||
formatError(axiosError: any): Error; | ||
private formatError; | ||
} | ||
export interface ClientOptions { | ||
disableSslVerification: boolean; | ||
proxy: string; | ||
disableSslVerification?: boolean; | ||
proxy?: string; | ||
headers?: object; | ||
@@ -27,0 +26,0 @@ logger?: Logger; |
@@ -22,2 +22,38 @@ "use strict"; | ||
*/ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -33,5 +69,4 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var DefaultHttpClient = /** @class */ (function () { | ||
function DefaultHttpClient(_a) { | ||
var _this = this; | ||
var _b = _a.proxy, proxy = _b === void 0 ? '' : _b, _c = _a.logger, logger = _c === void 0 ? undefined : _c, _d = _a.logLevel, logLevel = _d === void 0 ? logger_1.LogLevel.INFO : _d, _e = _a.headers, headers = _e === void 0 ? {} : _e; | ||
function DefaultHttpClient(options) { | ||
if (options === void 0) { options = {}; } | ||
// A request header consists of its case-insensitive name followed by a colon ':' | ||
@@ -43,11 +78,7 @@ // from: https://developer.mozilla.org/zh-TW/docs/Web/HTTP/Headers | ||
}; | ||
// proxy | ||
var proxyAgent; | ||
if (proxy && proxy !== '') { | ||
proxyAgent = HttpsProxyAgent(proxy); | ||
} | ||
this.defaultOption = options; | ||
// Logging | ||
if (typeof logger !== 'undefined') { | ||
this.logger = logger; | ||
if (typeof logLevel !== 'undefined') { | ||
if (typeof options.logger !== 'undefined') { | ||
this.logger = options.logger; | ||
if (typeof options.logLevel !== 'undefined') { | ||
this.logger.debug('The logLevel given to client was ignored as you also gave logger'); | ||
@@ -57,7 +88,16 @@ } | ||
else { | ||
this.logger = logger_1.getLogger(DefaultHttpClient.loggerName, logLevel, logger); | ||
this.logger = logger_1.getLogger(DefaultHttpClient.loggerName, options.logLevel || logger_1.LogLevel.ERROR, options.logger); | ||
} | ||
this.init(); | ||
} | ||
DefaultHttpClient.prototype.init = function () { | ||
var _this = this; | ||
// proxy | ||
var proxyAgent; | ||
if (this.defaultOption.proxy && this.defaultOption.proxy !== '') { | ||
proxyAgent = HttpsProxyAgent(this.defaultOption.proxy); | ||
} | ||
this.axiosInstance = axios_1.default.create({ | ||
maxContentLength: Infinity, | ||
headers: Object.assign(this.DEFAULT_HEADERS, headers), | ||
headers: Object.assign(this.DEFAULT_HEADERS, this.defaultOption.headers), | ||
proxy: false, | ||
@@ -73,3 +113,3 @@ httpAgent: proxyAgent, | ||
this.axiosInstance.interceptors.response.use(function (response) { | ||
var _a = response.config, url = _a.url, method = _a.method, status = response.status, statusText = response.statusText, data = response.data, headers = response.headers; | ||
var _a = response.config, url = _a.url, method = _a.method, status = response.status, statusText = response.statusText, headers = response.headers; | ||
var statusStr = ''; | ||
@@ -87,3 +127,3 @@ if (status && statusText) { | ||
var reponseLength = response.result ? JSON.stringify(response.result).length : 1; | ||
_this.logger.debug("Response: " + method.toUpperCase() + " " + statusStr + " " + url + " " + JSON.stringify(headers) + " " + JSON.stringify(data) + " " + reponseLength + " " + requestId); | ||
_this.logger.debug("Response: " + method.toUpperCase() + " " + statusStr + " " + url + " " + JSON.stringify(headers) + " " + reponseLength + " " + requestId); | ||
return response; | ||
@@ -94,55 +134,72 @@ }); | ||
this.logger.debug('initialized'); | ||
} | ||
}; | ||
DefaultHttpClient.prototype.sendRequest = function (httpRequest) { | ||
var _this = this; | ||
var endpoint = httpRequest.endpoint, queryParams = httpRequest.queryParams, method = httpRequest.method, data = httpRequest.data, headers = httpRequest.headers; | ||
headers = headers || {}; | ||
this.logger.debug("send request start: " + endpoint + " "); | ||
// Path params | ||
var url = endpoint; //parsePath(endpoint, pathParams); | ||
url = stripTrailingSlash(url); | ||
headers['User-Agent'] = "huaweicloud-usdk-nodejs/3.0"; | ||
var requestParams = { | ||
url: url, | ||
method: method, | ||
headers: headers, | ||
params: queryParams, | ||
data: data, | ||
paramsSerializer: function (params) { | ||
return querystring_1.stringify(params); | ||
}, | ||
}; | ||
var methods = ['PUT', 'POST', 'PATCH', 'DELETE']; | ||
if (method && methods.indexOf(method.toUpperCase()) !== -1) { | ||
requestParams = Object.assign(requestParams, { | ||
transformRequest: [this.transformOptions.bind(this)] | ||
}); | ||
} | ||
DefaultHttpClient.httpReqParam = requestParams; | ||
return this.axiosInstance(requestParams).then(function (res) { | ||
return this._request(httpRequest).then(function (res) { | ||
DefaultHttpClient.httpResponse = res; | ||
if (!res) { | ||
return; | ||
} | ||
; | ||
delete res.config; | ||
delete res.request; | ||
res.result = res.data; | ||
delete res.data; | ||
if (httpRequest['responseHeaders']) { | ||
var responseHeaders = httpRequest['responseHeaders']; | ||
for (var _i = 0, responseHeaders_1 = responseHeaders; _i < responseHeaders_1.length; _i++) { | ||
var item = responseHeaders_1[_i]; | ||
var lowerItem = item.toString().toLowerCase(); | ||
if (!res.result[item] && res.headers[lowerItem]) { | ||
res.result[item] = res.headers[lowerItem]; | ||
} | ||
} | ||
} | ||
return res; | ||
}, function (err) { | ||
var result = _this._convertResponse(httpRequest, res); | ||
return { | ||
data: result instanceof String ? undefined : result, | ||
statusCode: res.status, | ||
headers: res.headers | ||
}; | ||
}).catch(function (err) { | ||
// TODO: | ||
DefaultHttpClient.httpResponse = err; | ||
throw _this.formatError(err); | ||
var errorRespone = _this.formatError(err); | ||
_this.logger.error('some error found:', errorRespone); | ||
throw errorRespone; | ||
}); | ||
}; | ||
DefaultHttpClient.prototype._request = function (httpRequest) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var endpoint, queryParams, method, data, headers, url, requestParams, methods, res; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
endpoint = httpRequest.endpoint, queryParams = httpRequest.queryParams, method = httpRequest.method, data = httpRequest.data, headers = httpRequest.headers; | ||
headers = headers || {}; | ||
this.logger.debug("send request start: " + endpoint + " "); | ||
url = endpoint; | ||
url = stripTrailingSlash(url); | ||
headers['User-Agent'] = "huaweicloud-usdk-nodejs/3.0"; | ||
requestParams = { | ||
url: url, | ||
method: method, | ||
headers: headers, | ||
params: queryParams, | ||
data: data, | ||
paramsSerializer: function (params) { | ||
return querystring_1.stringify(params); | ||
}, | ||
}; | ||
methods = ['PUT', 'POST', 'PATCH', 'DELETE']; | ||
if (method && methods.indexOf(method.toUpperCase()) !== -1) { | ||
requestParams = Object.assign(requestParams, { | ||
transformRequest: [this.transformOptions.bind(this)] | ||
}); | ||
} | ||
// TODO | ||
DefaultHttpClient.httpReqParam = requestParams; | ||
return [4 /*yield*/, this.axiosInstance(requestParams)]; | ||
case 1: | ||
res = _a.sent(); | ||
return [2 /*return*/, res]; | ||
} | ||
}); | ||
}); | ||
}; | ||
DefaultHttpClient.prototype._convertResponse = function (httpRequest, axiosResult) { | ||
if (httpRequest['responseHeaders'] && axiosResult.data) { | ||
var responseHeaders = httpRequest['responseHeaders']; | ||
for (var _i = 0, responseHeaders_1 = responseHeaders; _i < responseHeaders_1.length; _i++) { | ||
var item = responseHeaders_1[_i]; | ||
var lowerItem = item.toString().toLowerCase(); | ||
if (!axiosResult.data[item] && axiosResult.headers[lowerItem]) { | ||
axiosResult.data[item] = axiosResult.headers[lowerItem]; | ||
} | ||
} | ||
} | ||
return axiosResult.data; | ||
}; | ||
DefaultHttpClient.prototype.transformOptions = function (data, headers) { | ||
@@ -160,66 +217,14 @@ if (headers['content-type'] === 'multipart/form-data') { | ||
}; | ||
/** | ||
* Format error returned by axios | ||
* @private | ||
* @returns {Error} | ||
* @param axiosError | ||
*/ | ||
DefaultHttpClient.prototype.formatError = function (axiosError) { | ||
// return an actual error object, | ||
// but make it flexible so we can add properties like 'body' | ||
var error = new Error(); | ||
// axios specific handling | ||
// this branch is for an error received from the service | ||
if (axiosError.response) { | ||
axiosError = axiosError.response; | ||
// The request was made and the server responded with a status code | ||
// that falls out of the range of 2xx | ||
delete axiosError.config; | ||
delete axiosError.request; | ||
error.statusText = axiosError.statusText; | ||
error.name = axiosError.statusText; // ** deprecated ** | ||
error.status = axiosError.status; | ||
error.code = axiosError.status; // ** deprecated ** | ||
error.message = parseServiceErrorMessage(axiosError.data) || axiosError.statusText; | ||
// some services bury the useful error message within 'data' | ||
// adding it to the error under the key 'body' as a string or object | ||
var errorBody = void 0; | ||
try { | ||
// try/catch to handle objects with circular references | ||
// errorBody = JSON.stringify(axiosError.data); | ||
errorBody = axiosError.data; | ||
} | ||
catch (e) { | ||
// ignore the error, use the object, and tack on a warning | ||
errorBody = axiosError.data; | ||
errorBody.warning = 'Body contains circular reference'; | ||
this.logger.error("Failed to stringify axiosError: " + e); | ||
} | ||
error.body = errorBody; | ||
// attach headers to error object | ||
error.headers = axiosError.headers; | ||
// print a more descriptive error message for auth issues | ||
if (isAuthenticationError(axiosError)) { | ||
error.message = 'Access is denied due to invalid credentials.'; | ||
} | ||
} | ||
else if (axiosError.request) { | ||
// The request was made but no response was received | ||
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of | ||
// http.ClientRequest in node.js | ||
error.message = axiosError.message; | ||
error.statusText = axiosError.code; | ||
error.body = axiosError.message; | ||
// when a request to a private cloud instance has an ssl problem, it never connects and follows this branch of the error handling | ||
if (isSelfSignedCertificateError(axiosError)) { | ||
error.message = "The connection failed because the SSL certificate is not valid. " + | ||
"To use a self-signed certificate, set the `disableSslVerification` parameter in the constructor options."; | ||
} | ||
} | ||
else { | ||
// Something happened in setting up the request that triggered an Error | ||
error.message = axiosError.message; | ||
} | ||
this.logger.error("some error found:", error); | ||
return error; | ||
DefaultHttpClient.prototype.formatError = function (error) { | ||
var _a; | ||
var transformedResponse = { | ||
data: error.response ? error.response.data : undefined, | ||
status: error.response ? error.response.status : undefined, | ||
headers: error.response ? error.response.headers : undefined, | ||
message: error.message || undefined, | ||
config: error.config, | ||
originalError: error, | ||
requestId: (_a = error.response) === null || _a === void 0 ? void 0 : _a.headers['x-request-id'] | ||
}; | ||
return transformedResponse; | ||
}; | ||
@@ -235,71 +240,1 @@ DefaultHttpClient.loggerName = "DefaultHttpClient"; | ||
} | ||
/** | ||
* Determine if the error is due to bad credentials | ||
* @private | ||
* @param {Object} error - error object returned from axios | ||
* @returns {boolean} true if error is due to authentication | ||
*/ | ||
function isAuthenticationError(error) { | ||
var isAuthErr = false; | ||
var code = error.status || null; | ||
var body = error.data || {}; | ||
// handle specific error from iam service, should be relevant across platforms | ||
var isIamServiceError = body.context && | ||
body.context.url && | ||
body.context.url.indexOf('iam') > -1; | ||
if (code === 401 || code === 403 || isIamServiceError) { | ||
isAuthErr = true; | ||
} | ||
return isAuthErr; | ||
} | ||
/** | ||
* Look for service error message in common places, by priority | ||
* first look in `errors[0].message`, then in `error`, then in | ||
* `message`, then in `errorMessage` | ||
* @private | ||
* @param {Object} response - error response body received from service | ||
* @returns {string | undefined} the error message if is was found, undefined otherwise | ||
*/ | ||
function parseServiceErrorMessage(response) { | ||
var message; | ||
if (Array.isArray(response.errors) && response.errors.length > 0 && hasStringProperty(response.errors[0], 'message')) { | ||
message = response.errors[0].message; | ||
} | ||
else if (hasStringProperty(response, 'error')) { | ||
message = response.error; | ||
} | ||
else if (hasStringProperty(response, 'message')) { | ||
message = response.message; | ||
} | ||
else if (hasStringProperty(response, 'errorMessage')) { | ||
message = response.errorMessage; | ||
} | ||
return message; | ||
} | ||
/** | ||
* Return true if object has a specified property that is a string | ||
* @private | ||
* @param {Object} obj - object to look for property in | ||
* @param {string} property - name of the property to look for | ||
* @returns {boolean} true if property exists and is string | ||
*/ | ||
function hasStringProperty(obj, property) { | ||
return Boolean(obj[property] && typeof obj[property] === 'string'); | ||
} | ||
/** | ||
* Determine if the error is due to a bad self signed certificate | ||
* @private | ||
* @param {Object} error - error object returned from axios | ||
* @returns {boolean} true if error is due to an SSL error | ||
*/ | ||
function isSelfSignedCertificateError(error) { | ||
var result = false; | ||
var sslCode = 'DEPTH_ZERO_SELF_SIGNED_CERT'; | ||
var sslMessage = 'self signed certificate'; | ||
var hasSslCode = error.code === sslCode; | ||
var hasSslMessage = hasStringProperty(error, 'message') && error.message.includes(sslMessage); | ||
if (hasSslCode || hasSslMessage) { | ||
result = true; | ||
} | ||
return result; | ||
} |
@@ -0,4 +1,5 @@ | ||
import { DefaultHttpResponse } from "./DefaultHttpResponse"; | ||
import { IHttpRequest } from "./IHttpRequest"; | ||
export interface HttpClient { | ||
sendRequest(httpRequest: IHttpRequest): Promise<any>; | ||
sendRequest<T>(httpRequest: IHttpRequest): Promise<DefaultHttpResponse<T>>; | ||
} |
export interface IHttpRequest { | ||
params: any; | ||
endpoint: string | undefined; | ||
contentType: string | undefined; | ||
method: string | undefined; | ||
queryParams: any; | ||
pathParams: any; | ||
headers: any; | ||
data: any; | ||
getPathParams: () => any; | ||
responseHeaders: any; | ||
params?: any; | ||
endpoint?: string | undefined; | ||
contentType?: string | undefined; | ||
method?: string | undefined; | ||
queryParams?: any; | ||
pathParams?: any; | ||
headers?: any; | ||
data?: any; | ||
proxy?: any; | ||
getPathParams?: () => any; | ||
responseHeaders?: any; | ||
} | ||
@@ -13,0 +14,0 @@ export declare class HttpRequestImpl implements IHttpRequest { |
{ | ||
"name": "@huaweicloud/huaweicloud-sdk-core", | ||
"version": "3.0.9-beta", | ||
"version": "3.0.10-beta", | ||
"description": "Core code for Huaweicloud SDK for Node.js", | ||
@@ -11,3 +11,3 @@ "main": "huaweicloud-sdk-core.js", | ||
"lint": "tslint --project .", | ||
"test": "npm run build && nyc mocha --config .mocharc.json tests/**/*.spec.js" | ||
"test": "npm run build && nyc mocha --config .mocharc.json tests/**/*.spec.ts" | ||
}, | ||
@@ -31,3 +31,4 @@ "repository": { | ||
"moment": "^2.27.0", | ||
"moment-timezone": "^0.5.31" | ||
"moment-timezone": "^0.5.31", | ||
"ramda": "^0.27.1" | ||
}, | ||
@@ -37,8 +38,16 @@ "devDependencies": { | ||
"@types/mocha": "^8.2.2", | ||
"@types/chai-like": "^1.1.0", | ||
"@types/chai-spies": "^1.0.3", | ||
"@types/chai-things": "^0.0.34", | ||
"busboy": "^0.3.1", | ||
"chai": "^4.3.4", | ||
"chai-like": "^1.1.1", | ||
"chai-spies": "^1.0.0", | ||
"chai-things": "^0.2.0", | ||
"mocha": "^8.3.2", | ||
"moxios": "^0.4.0", | ||
"nock": "^13.1.0", | ||
"nyc": "^15.1.0", | ||
"shx": "^0.3.2", | ||
"sinon": "^11.1.1", | ||
"ts-node": "^9.1.1", | ||
@@ -45,0 +54,0 @@ "tslint": "^6.1.3", |
export declare class SdkResponse { | ||
private httpStatusCode; | ||
result?: any; | ||
constructor(statusCode?: number); | ||
getStatusCode(): number; | ||
setStatusCode(code: number): void; | ||
setResult(result: any): void; | ||
getResult(): any; | ||
httpStatusCode?: number; | ||
} |
@@ -25,19 +25,6 @@ "use strict"; | ||
var SdkResponse = /** @class */ (function () { | ||
function SdkResponse(statusCode) { | ||
this.httpStatusCode = statusCode; | ||
function SdkResponse() { | ||
} | ||
SdkResponse.prototype.getStatusCode = function () { | ||
return this.httpStatusCode; | ||
}; | ||
SdkResponse.prototype.setStatusCode = function (code) { | ||
this.httpStatusCode = code; | ||
}; | ||
SdkResponse.prototype.setResult = function (result) { | ||
this.result = result; | ||
}; | ||
SdkResponse.prototype.getResult = function () { | ||
return this.result; | ||
}; | ||
return SdkResponse; | ||
}()); | ||
exports.SdkResponse = SdkResponse; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
113103
52
12
19
2021
+ Addedramda@^0.27.1
+ Addedramda@0.27.2(transitive)