Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private buildRuleResponse(response: HttpOperationResponse): RuleResponse {
try {
const rule = buildRule(response.parsedBody);
const ruleResponse: RuleResponse = Object.assign(rule || {}, { _response: response });
return ruleResponse;
} catch (err) {
log.warning("Failure parsing response from service - %0 ", err);
throw new RestError(
`Error occurred while parsing the response body - cannot form a rule object using the response from the service.`,
RestError.PARSE_ERROR,
response.status,
stripRequest(response.request),
stripResponse(response)
);
}
}
}
const rules: Rule[] = [];
if (!Array.isArray(response.parsedBody)) {
throw new TypeError(`${response.parsedBody} was expected to be of type Array`);
}
const rawRuleArray: any = response.parsedBody;
for (let i = 0; i < rawRuleArray.length; i++) {
const rule = buildRule(rawRuleArray[i]);
if (rule) {
rules.push(rule);
}
}
const listRulesResponse: ListRulesResponse = Object.assign(rules, { _response: response });
return listRulesResponse;
} catch (err) {
log.warning("Failure parsing response from service - %0 ", err);
throw new RestError(
`Error occurred while parsing the response body - cannot form a list of rules using the response from the service.`,
RestError.PARSE_ERROR,
response.status,
stripRequest(response.request),
stripResponse(response)
);
}
}
const topics: TopicDetails[] = [];
if (!Array.isArray(response.parsedBody)) {
throw new TypeError(`${response.parsedBody} was expected to be of type Array`);
}
const rawTopicArray: any = response.parsedBody;
for (let i = 0; i < rawTopicArray.length; i++) {
const topic = buildTopic(rawTopicArray[i]);
if (topic) {
topics.push(topic);
}
}
const listTopicsResponse: ListTopicsResponse = Object.assign(topics, { _response: response });
return listTopicsResponse;
} catch (err) {
log.warning("Failure parsing response from service - %0 ", err);
throw new RestError(
`Error occurred while parsing the response body - cannot form a list of topics using the response from the service.`,
RestError.PARSE_ERROR,
response.status,
stripRequest(response.request),
stripResponse(response)
);
}
}
private buildQueueResponse(response: HttpOperationResponse): QueueResponse {
try {
const queue = buildQueue(response.parsedBody);
const queueResponse: QueueResponse = Object.assign(queue || {}, { _response: response });
return queueResponse;
} catch (err) {
log.warning("Failure parsing response from service - %0 ", err);
throw new RestError(
`Error occurred while parsing the response body - cannot form a queue object using the response from the service.`,
RestError.PARSE_ERROR,
response.status,
stripRequest(response.request),
stripResponse(response)
);
}
}
private buildSubscriptionResponse(response: HttpOperationResponse): SubscriptionResponse {
try {
const subscription = buildSubscription(response.parsedBody);
const subscriptionResponse: SubscriptionResponse = Object.assign(subscription || {}, {
_response: response
});
return subscriptionResponse;
} catch (err) {
log.warning("Failure parsing response from service - %0 ", err);
throw new RestError(
`Error occurred while parsing the response body - cannot form a subscription object using the response from the service.`,
RestError.PARSE_ERROR,
response.status,
stripRequest(response.request),
stripResponse(response)
);
}
}
throw new TypeError(`${response.parsedBody} was expected to be of type Array`);
}
const rawSubscriptionArray: any = response.parsedBody;
for (let i = 0; i < rawSubscriptionArray.length; i++) {
const subscription = buildSubscription(rawSubscriptionArray[i]);
if (subscription) {
subscriptions.push(subscription);
}
}
const listSubscriptionsResponse: ListSubscriptionsResponse = Object.assign(subscriptions, {
_response: response
});
return listSubscriptionsResponse;
} catch (err) {
log.warning("Failure parsing response from service - %0 ", err);
throw new RestError(
`Error occurred while parsing the response body - cannot form a list of subscriptions using the response from the service.`,
RestError.PARSE_ERROR,
response.status,
stripRequest(response.request),
stripResponse(response)
);
}
}
private async getResource(
name: string,
serializer: AtomXmlSerializer
): Promise {
const webResource: WebResource = new WebResource(this.getUrl(name), "GET");
const response = await executeAtomXmlOperation(this, webResource, serializer);
if (
response.parsedBody == undefined ||
(Array.isArray(response.parsedBody) && response.parsedBody.length == 0)
) {
const err = new RestError(
`The messaging entity "${name}" being requested cannot be found.`,
"404",
404,
stripRequest(webResource),
stripResponse(response)
);
throw err;
}
return response;
}
if (Array.isArray(result)) {
result.forEach((entry: object) => {
setName(entry, nameProperties);
});
} else {
setName(result, nameProperties);
}
response.parsedBody = result;
return;
}
log.error(
"Failure in parsing response body from service. Expected response to be in Atom XML format and have either feed or entry components, but received - %0",
atomResponseInJson
);
throw new RestError(
"Error occurred while parsing the response body - expected the service to return atom xml content with either feed or entry elements.",
RestError.PARSE_ERROR,
response.status,
stripRequest(response.request),
stripResponse(response)
);
}