in Extensions/ArtifactEngine/Providers/typed-rest-client/RestClient.ts [175:229]
private async _processResponse<T>(res: httpm.HttpClientResponse, options: IRequestOptions): Promise<IRestResponse<T>> {
return new Promise<IRestResponse<T>>(async (resolve, reject) => {
let rres: IRestResponse<T> = <IRestResponse<T>>{};
let statusCode: number = res.message.statusCode;
rres.statusCode = statusCode;
// not found leads to null obj returned
if (statusCode == httpm.HttpCodes.NotFound) {
resolve(rres);
}
let obj: any;
// get the result from the body
try {
let contents: string = await res.readBody();
if (contents && contents.length > 0) {
obj = JSON.parse(contents);
if (options && options.responseProcessor) {
rres.result = options.responseProcessor(obj);
}
else {
rres.result = obj;
}
}
}
catch (err) {
// Invalid resource (contents not json); leaving result obj null
}
// note that 3xx redirects are handled by the http layer.
if (statusCode > 299) {
let msg: string;
// if exception/error in body, attempt to get better error
if (obj && obj.message) {
msg = obj.message;
} else {
msg = "Failed request: (" + statusCode + ")";
}
let err: Error = new Error(msg);
// attach statusCode and body obj (if available) to the error object
err['statusCode'] = statusCode;
if (rres.result) {
err['result'] = rres.result;
}
reject(err);
} else {
resolve(rres);
}
});
}