2021-03-14 08:42:46 +01:00
|
|
|
import { IncomingMessage } from 'http';
|
2019-12-15 23:04:11 +01:00
|
|
|
import request from 'request';
|
|
|
|
|
|
|
|
export function callRegistry(url: string): Promise<string> {
|
2021-03-14 08:42:46 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
let options = {
|
|
|
|
url: url,
|
2020-08-13 23:36:23 +02:00
|
|
|
headers: { Accept: 'application/json' },
|
2021-03-14 08:42:46 +01:00
|
|
|
};
|
|
|
|
// @ts-ignore
|
|
|
|
request(options, (error: any, response: IncomingMessage, body: string) => {
|
|
|
|
if (error) {
|
|
|
|
reject(error);
|
|
|
|
// @ts-ignore
|
|
|
|
} else if (response.statusCode >= 400) {
|
|
|
|
reject(new Error(`Requesting "${url}" returned status code ${response.statusCode}.`));
|
|
|
|
} else {
|
|
|
|
resolve(body);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2019-12-15 23:04:11 +01:00
|
|
|
}
|