1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-25 23:21:29 +03:00

M #~: fix error xmlrpc (#1517)

Co-authored-by: Jorge Lobo <jlobo@opennebula.systems>
This commit is contained in:
Jorge Miguel Lobo Escalona 2021-10-08 14:24:22 +02:00 committed by GitHub
parent 495355bfc4
commit 79c55f38c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 21 deletions

View File

@ -156,7 +156,11 @@ router.all(
const response = (val = {}) => {
switch (typeof val) {
case 'string':
res.locals.httpCode = httpResponse(notFound, val)
try {
res.locals.httpCode = httpResponse(ok, JSON.parse(val))
} catch (error) {
res.locals.httpCode = httpResponse(notFound, val)
}
break
case 'object':
res.locals.httpCode = httpResponse(ok, val)

View File

@ -118,37 +118,29 @@ const opennebulaConnect = (username = '', password = '', zoneURL = '') => {
}
if (
result &&
result.METHODRESPONSE &&
result.METHODRESPONSE.PARAMS &&
result.METHODRESPONSE.PARAMS.PARAM &&
result.METHODRESPONSE.PARAMS.PARAM.VALUE &&
result.METHODRESPONSE.PARAMS.PARAM.VALUE.ARRAY &&
result.METHODRESPONSE.PARAMS.PARAM.VALUE.ARRAY.DATA &&
result.METHODRESPONSE.PARAMS.PARAM.VALUE.ARRAY.DATA
.VALUE &&
result.methodResponse &&
result.methodResponse.fault &&
result.methodResponse.fault.value &&
result.methodResponse.fault.value.struct &&
result.methodResponse.fault.value.struct.member &&
Array.isArray(
result.METHODRESPONSE.PARAMS.PARAM.VALUE.ARRAY.DATA
.VALUE
result.methodResponse.fault.value.struct.member
)
) {
const errorData = result.METHODRESPONSE.PARAMS.PARAM.VALUE.ARRAY.DATA.VALUE.filter(
element => element.STRING
const errorData = result.methodResponse.fault.value.struct.member.find(
element => element.value && element.value.string
)
if (
Array.isArray(errorData) &&
errorData[0] &&
errorData[0].STRING
) {
if (errorData) {
// success
fillHookResource && fillResourceforHookConnection(username, action, parameters)
callback(undefined, errorData[0].STRING)
callback(undefined, errorData.value.string)
}
}
})
return
} else if (value && value[0] && value[1]) {
let messageCall
if (Array.isArray(value) && value[0] && value[1]) {
if (Array.isArray(value)) {
messageCall = value[1]
} else if (value.length > 0) {
messageCall = value
@ -163,7 +155,7 @@ const opennebulaConnect = (username = '', password = '', zoneURL = '') => {
fillHookResource && fillResourceforHookConnection(username, action, parameters)
callback(
undefined,
error === null && result === null ? messageCall : result
error === null && !String(result) ? JSON.stringify(messageCall) : result
)
})
return