UNPKG

@overture-stack/lyric

Version:
31 lines (30 loc) 1.28 kB
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) { try { const dictionaryFetchResult = await dictionaryRestClient.getDictionary(schemaServiceUrl, { name, version }); if (dictionaryFetchResult.success) { return dictionaryFetchResult.data; } else { logger.error(`Failed to fetch dictionary from schema service.`, dictionaryFetchResult.message); throw new BadRequest(`Schema with name '${name}' and version '${version}' not found`); } } catch (error) { logger.error(LOG_MODULE, `Error Fetching dictionary from lectern`, error); throw new ServiceUnavailable(); } }, }; }; export default client;