All files / scripts/imf/errors weo-sdmx-only.ts

100% Statements 7/7
100% Branches 0/0
100% Functions 1/1
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36                                            4x 4x 4x         4x 4x 4x 4x      
/**
 * @module imf/errors/weo-sdmx-only
 * @description Diagnostic error for WEO indicators that the Datamapper
 * does not serve (returns an empty envelope) and require SDMX 3.0.
 *
 * @author Hack23 AB
 * @license Apache-2.0
 */
 
import { weoSdmxPath } from '../indicators/weo.js';
 
/**
 * Thrown by `ImfClient.getWeoIndicator` when the requested code lives
 * in `IMF_WEO_SDMX_ONLY` (i.e. the Datamapper transport returned zero
 * points). Carries the SDMX path the caller should use instead so
 * agents can recover programmatically.
 */
export class ImfWeoSdmxOnlyError extends Error {
  readonly weoCode: string;
  readonly countryCode: string;
  readonly sdmxPath: string;
  constructor(iso3: string, weoCode: string) {
    const normalisedIso3 = iso3.toUpperCase();
    const sdmxPath = weoSdmxPath(normalisedIso3, weoCode);
    super(
      `IMF WEO indicator '${weoCode}' is not exposed by the Datamapper for '${normalisedIso3}'. ` +
        `Use sdmxFetch('${sdmxPath}') with IMF_SDMX_SUBSCRIPTION_KEY set, or the ` +
        `'imf-fetch sdmx --path ${sdmxPath} --indicator ${weoCode} --country ${normalisedIso3}' CLI.`,
    );
    this.name = 'ImfWeoSdmxOnlyError';
    this.weoCode = weoCode;
    this.countryCode = normalisedIso3;
    this.sdmxPath = sdmxPath;
  }
}