in src/utils/request-manager.ts [52:95]
private makeApiRequest(method: string, endpoint: string, requestBody: string, expectResponseBody: boolean, contentType: string): Promise<JsonResponse> {
return new Promise<any>((resolve, reject) => {
var request: superagent.Request = (<any>superagent)[method](this._serverUrl + endpoint);
if (this._proxy) (<any>request).proxy(this._proxy);
this.attachCredentials(request);
if (requestBody) {
if (contentType) {
request = request.set("Content-Type", contentType);
}
request = request.send(requestBody);
}
request.end((err: any, res: superagent.Response) => {
if (err) {
reject(this.getCodePushError(err, res));
return;
}
try {
var body = JSON.parse(res.text);
} catch (err) {
}
if (res.ok) {
if (expectResponseBody && !body) {
reject(<CodePushError>{ message: `Could not parse response: ${res.text}`, statusCode: RequestManager.ERROR_INTERNAL_SERVER });
} else {
resolve(<JsonResponse>{
headers: res.header,
body: body
});
}
} else {
if (body) {
reject(<CodePushError>{ message: body.message, statusCode: this.getErrorStatus(err, res) });
} else {
reject(<CodePushError>{ message: res.text, statusCode: this.getErrorStatus(err, res) });
}
}
});
})
}