@overture-stack/lyric
Version:
Data Submission system
29 lines (28 loc) • 1.07 kB
JavaScript
import { rest as dictionaryRestClient } from '@overture-stack/lectern-client';
import { BadRequest, ServiceUnavailable } from '../utils/errors.js';
const client = (schemaServiceUrl, logger) => {
const LOG_MODULE = 'LECTERN_CLIENT';
return {
/**
* Fetch a Dictionary using Schema Service(Lectern)
* @param name Dictionary Name
* @param version Dictionary version
* @returns A Dictionary found
*/
async fetchDictionaryByVersion(name, version) {
let newSchema;
try {
newSchema = await dictionaryRestClient.fetchSchema(schemaServiceUrl, name, version);
}
catch (error) {
logger.error(LOG_MODULE, `Error Fetching dictionary from lectern`, error);
throw new ServiceUnavailable();
}
if (!newSchema) {
throw new BadRequest(`Schema with name '${name}' and version '${version}' not found`);
}
return newSchema;
},
};
};
export default client;