diff --git a/lib/core.js b/lib/core.js index c57967d09..ce3f3e051 100644 --- a/lib/core.js +++ b/lib/core.js @@ -1611,16 +1611,19 @@ if (!data.error && !data.status_code) { console.warn('No error param in registerFetchError data', data); } else if (data.error) { - // Convert runtime `error` to `error_code` and `error_message`. if (typeof data.error === 'string') { fetch_data.error_code = data.error } else { + // Convert runtime `error` to `error_code` and `error_message`. if (data.error.code) { fetch_data.error_code = data.error.code; } if (data.error.message) { fetch_data.error_message = data.error.message; } + if (data.error.name) { + fetch_data.error_code = data.error.name; + } if (!data.error.code && !data.error.message) { fetch_data.error_message = '' + data.error; } diff --git a/lib/request.js b/lib/request.js index 2a13ee4fd..3ca318cb9 100644 --- a/lib/request.js +++ b/lib/request.js @@ -70,7 +70,7 @@ export default function(options, iframely_options, callback) { var prefix = CONFIG.API_REQUEST_CACHE_PREFIX ? (CONFIG.API_REQUEST_CACHE_PREFIX + ':') : ''; - var lang = iframely_options.getProviderOptions('locale'); + var lang = iframely_options?.getProviderOptions('locale'); if (lang) { prefix += lang + ':'; } @@ -94,13 +94,13 @@ export default function(options, iframely_options, callback) { } if (error) { - iframely_options.registerFetchError({ + iframely_options?.registerFetchError({ source: 'api', url: options.uri, error: error }); } else if (result && result.status !== 200) { - iframely_options.registerFetchError({ + iframely_options?.registerFetchError({ source: 'api', url: options.uri, status_code: result.status @@ -153,7 +153,7 @@ export default function(options, iframely_options, callback) { }); } - iframely_options.registerFetch({ + iframely_options?.registerFetch({ source: 'api', url: options.uri }); @@ -171,7 +171,7 @@ export default function(options, iframely_options, callback) { } // Ignore proxy.cache_ttl, if options.cache_ttl === 0 - do not read from cache. - if (iframely_options.cache_ttl === 0) { + if (iframely_options?.cache_ttl === 0) { if (useCacheOnly) { @@ -197,7 +197,7 @@ export default function(options, iframely_options, callback) { } } - iframely_options.registerFetch({ + iframely_options?.registerFetch({ source: 'cache', url: options.uri });