UNPKG

892 BJavaScriptView Raw
1'use strict';
2
3const fetchres = require('fetchres');
4const logger = require('@financial-times/n-logger').default;
5const eagerFetch = require('./utils/eager-fetch');
6
7module.exports = function (uuid, taxonomy, opts) {
8 const url = 'https://next-v1tov2-mapping-dev.herokuapp.com/concordance_mapping_v1tov2/' + taxonomy + '/' + uuid;
9 const retry = (opts || {}).retry;
10
11 return eagerFetch(url, {
12 timeout: 3000,
13 retry: retry
14 })
15 .then(function (response) {
16 if (!response.ok) {
17 logger.warn('Failed to get mapping', {
18 uuid: uuid,
19 taxonomy: taxonomy,
20 status: response.status
21 });
22 }
23 return response;
24 })
25 .then(fetchres.json)
26 .then(function (data) {
27 if (!data.concordance_map || !data.concordance_map.v2) {
28 throw new Error('Mapping doesn‘t exist');
29 } else {
30 return data.concordance_map.v2.enriched_goodness;
31 }
32 });
33};