Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
);
}
}
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;
}
const response: HttpOperationResponse = await serviceBusAtomManagementClient.sendRequest(
webResource
);
log.httpAtomXml(`Received ATOM based HTTP response: ${response.bodyAsText}`);
try {
if (response.bodyAsText) {
response.parsedBody = await parseXML(response.bodyAsText, { includeRoot: true });
}
} catch (err) {
const error = new RestError(
`Error occurred while parsing the response body - expected the service to return valid xml content.`,
RestError.PARSE_ERROR,
response.status,
stripRequest(response.request),
stripResponse(response)
);
log.warning("Error parsing response body from Service - %0", err);
throw error;
}
return serializer.deserialize(response);
}
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)
);
}
}
}
private buildTopicResponse(response: HttpOperationResponse): TopicResponse {
try {
const topic = buildTopic(response.parsedBody);
const topicResponse: TopicResponse = Object.assign(topic || {}, { _response: response });
return topicResponse;
} catch (err) {
log.warning("Failure parsing response from service - %0 ", err);
throw new RestError(
`Error occurred while parsing the response body - cannot form a topic object using the response from the service.`,
RestError.PARSE_ERROR,
response.status,
stripRequest(response.request),
stripResponse(response)
);
}
}