Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function testDaskDashboard(
url: string,
settings: ServerConnection.ISettings
): Promise {
url = normalizeDashboardUrl(url);
// If this is a url that we are proxying under the notebook server,
// it is easier to check for a valid dashboard.
if (URLExt.isLocal(url)) {
return ServerConnection.makeRequest(
URLExt.join(settings.baseUrl, url, 'individual-plots.json'),
{},
settings
).then(response => {
if (response.status === 200) {
return true;
} else {
return false;
}
});
}
return new Promise(resolve => {
// Hack Alert! We would like to test whether a given URL is actually
// a dask dashboard, since we will be iframe-ing it sight-unseen.
// However, CORS policies prevent us from doing a normal fetch
it('should create a server error from a server response', async () => {
const settings = getRequestHandler(200, 'hi');
const init = { body: 'hi', method: 'POST' };
const response = await ServerConnection.makeRequest(
settings.baseUrl,
init,
settings
);
const err = new ServerConnection.ResponseError(response);
expect(err.message).to.equal('Invalid response: 200 OK');
});
});
private async _stopById(id: string): Promise {
const response = await ServerConnection.makeRequest(
`${this._serverSettings.baseUrl}dask/clusters/${id}`,
{ method: 'DELETE' },
this._serverSettings
);
if (response.status !== 204) {
const err = await response.json();
void showErrorMessage('Failed to close cluster', err);
throw err;
}
await this._updateClusterList();
}
export async function factory(): Promise {
const request = ServerConnection.makeRequest(
METRIC_URL,
{},
SERVER_CONNECTION_SETTINGS
);
const response = await request;
if (response.ok) {
try {
return await response.json();
} catch (error) {
throw error;
}
}
return null;
}
export async function factory(): Promise {
const request = ServerConnection.makeRequest(
METRIC_URL,
{},
SERVER_CONNECTION_SETTINGS
);
const response = await request;
if (response.ok) {
try {
return await response.json();
} catch (error) {
throw error;
}
}
return null;
}
private async _updateClusterList(): Promise {
const response = await ServerConnection.makeRequest(
`${this._serverSettings.baseUrl}dask/clusters`,
{},
this._serverSettings
);
if (response.status !== 200) {
const msg =
'Failed to list clusters: might the server extension not be installed/enabled?';
const err = new Error(msg);
if (!this._serverErrorShown) {
showErrorMessage('Dask Server Error', err);
this._serverErrorShown = true;
}
throw err;
}
const data = (await response.json()) as IClusterModel[];
this._clusters = data;
function httpRequest(
url: string,
method: string,
request?: Object
): Promise {
let fullRequest: RequestInit = {
method: method,
body: JSON.stringify(request)
};
let setting = ServerConnection.makeSettings();
let fullUrl = URLExt.join(setting.baseUrl, url);
return ServerConnection.makeRequest(fullUrl, fullRequest, setting);
}
function requestApiPromise(
baseUrl: string,
apiPath: string,
argument: any): Promise {
const url = URLExt.join(urlRStrip(baseUrl), apiPath);
let request = {
method: 'POST',
body: JSON.stringify(argument),
};
let settings = ServerConnection.makeSettings();
return ServerConnection.makeRequest(url, request, settings)
.then(handleError);
}