Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async getSchema(schemaRequest: SchemaRequest): Promise {
const variant = schemaRequest.getVariant();
if (!variant) {
return Promise.reject(
new Error(
`Please provide the schema variant by schemaRequest.withVariant()`
)
);
}
const request = await RequestFactory.create(
"artifact",
this.apiVersion,
this.settings
).catch(error => Promise.reject(error));
const response = await ArtifactApi.getArtifactUsingGET(request, {
artifactHrn: variant.url
}).catch(() => Promise.reject(`Cannot download schema bundle`));
if (response.status === 200) {
return response.arrayBuffer();
}
const messages: { [key: number]: string } = {
401: "You are not authorized to view the schema",
403: "Accessing the schema is forbidden",
404: "The schema was not found",
500: "Internal server error"
};
const message = response.statusText || messages[response.status];
return Promise.reject(
`Artifact Service error: HTTP ${response.status}: ${message}`