@alicloud/pop-core
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -9,2 +9,3 @@ 'use strict'; | ||
const httpx = require('httpx'); | ||
const xml2js = require('xml2js'); | ||
const debug = require('debug')('roa'); | ||
@@ -18,2 +19,28 @@ | ||
function parseXML(xml) { | ||
const parser = new xml2js.Parser({ | ||
// explicitArray: false | ||
}); | ||
return new Promise((resolve, reject) => { | ||
parser.parseString(xml, (err, result) => { | ||
if (err) { | ||
return reject(err); | ||
} | ||
resolve(result); | ||
}); | ||
}); | ||
} | ||
class ACSError extends Error { | ||
constructor(err) { | ||
const message = err.Message[0]; | ||
const code = err.Code[0]; | ||
const hostid = err.HostId[0]; | ||
const requestid = err.RequestId[0]; | ||
super(`${message} hostid: ${hostid}, requestid: ${requestid}`); | ||
this.code = code; | ||
} | ||
} | ||
class ROAClient { | ||
@@ -146,2 +173,3 @@ constructor(config) { | ||
const contentType = response.headers['content-type'] || ''; | ||
// JSON | ||
if (contentType.startsWith('application/json')) { | ||
@@ -160,2 +188,12 @@ var result = JSON.parse(body); | ||
if (contentType.startsWith('text/xml')) { | ||
return parseXML(body).then((result) => { | ||
if (result.Error) { | ||
return Promise.reject(new ACSError(result.Error)); | ||
} | ||
return result; | ||
}); | ||
} | ||
return body; | ||
@@ -162,0 +200,0 @@ }); |
{ | ||
"name": "@alicloud/pop-core", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "AliCloud POP SDK core", | ||
@@ -24,3 +24,4 @@ "main": "index.js", | ||
"httpx": "^2.1.2", | ||
"kitx": "^1.2.1" | ||
"kitx": "^1.2.1", | ||
"xml2js": "^0.4.17" | ||
}, | ||
@@ -27,0 +28,0 @@ "files": [ |
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
14246
353
3
+ Addedxml2js@^0.4.17
+ Addedsax@1.4.1(transitive)
+ Addedxml2js@0.4.23(transitive)
+ Addedxmlbuilder@11.0.1(transitive)