33 lines
1.3 KiB
JavaScript
33 lines
1.3 KiB
JavaScript
import { APIResult } from "$lib/auth";
|
|
import { Logger, logSetup } from "$lib/logger";
|
|
import { PUBLIC_BASE_URL } from "$env/static/public";
|
|
logSetup();
|
|
const logger = new Logger("netcreate.ts");
|
|
export async function createNetwork(token, cidr) {
|
|
logger.info('creating network');
|
|
try {
|
|
logger.debug(`api call: baseurl ${PUBLIC_BASE_URL}`);
|
|
const resp = await fetch(`${PUBLIC_BASE_URL}/v1/organization`, {
|
|
'method': 'POST',
|
|
'body': JSON.stringify({
|
|
cidr: `${cidr}`
|
|
}),
|
|
'headers': {
|
|
'Content-Type': 'application/json',
|
|
'Authorization': `Bearer ${token}`
|
|
}
|
|
});
|
|
if (!resp.ok) {
|
|
logger.error('call returned error code');
|
|
const rawerror = JSON.parse(await resp.text()).errors[0];
|
|
logger.error(`error sending org create: ${rawerror.message}`);
|
|
return [APIResult.Failed, { code: rawerror.code, message: rawerror.message }];
|
|
}
|
|
return [APIResult.Successful, await resp.json()];
|
|
}
|
|
catch (e) {
|
|
logger.error(`error making API request: ${e}`);
|
|
return [APIResult.Failed, { code: "api_call_failed", message: `${e}` }];
|
|
}
|
|
}
|
|
//# sourceMappingURL=netcreate.js.map
|