Skip to content

Commit dc17cbb

Browse files
authored
Request: make iframely_options optional (#680)
* request: make `iframely_options` optional * better error code extraction in `registerFetchError` * remove complex logic
1 parent bff7ac5 commit dc17cbb

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

lib/core.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1611,16 +1611,19 @@
16111611
if (!data.error && !data.status_code) {
16121612
console.warn('No error param in registerFetchError data', data);
16131613
} else if (data.error) {
1614-
// Convert runtime `error` to `error_code` and `error_message`.
16151614
if (typeof data.error === 'string') {
16161615
fetch_data.error_code = data.error
16171616
} else {
1617+
// Convert runtime `error` to `error_code` and `error_message`.
16181618
if (data.error.code) {
16191619
fetch_data.error_code = data.error.code;
16201620
}
16211621
if (data.error.message) {
16221622
fetch_data.error_message = data.error.message;
16231623
}
1624+
if (data.error.name) {
1625+
fetch_data.error_code = data.error.name;
1626+
}
16241627
if (!data.error.code && !data.error.message) {
16251628
fetch_data.error_message = '' + data.error;
16261629
}

lib/request.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default function(options, iframely_options, callback) {
7070

7171
var prefix = CONFIG.API_REQUEST_CACHE_PREFIX ? (CONFIG.API_REQUEST_CACHE_PREFIX + ':') : '';
7272

73-
var lang = iframely_options.getProviderOptions('locale');
73+
var lang = iframely_options?.getProviderOptions('locale');
7474
if (lang) {
7575
prefix += lang + ':';
7676
}
@@ -94,13 +94,13 @@ export default function(options, iframely_options, callback) {
9494
}
9595

9696
if (error) {
97-
iframely_options.registerFetchError({
97+
iframely_options?.registerFetchError({
9898
source: 'api',
9999
url: options.uri,
100100
error: error
101101
});
102102
} else if (result && result.status !== 200) {
103-
iframely_options.registerFetchError({
103+
iframely_options?.registerFetchError({
104104
source: 'api',
105105
url: options.uri,
106106
status_code: result.status
@@ -153,7 +153,7 @@ export default function(options, iframely_options, callback) {
153153
});
154154
}
155155

156-
iframely_options.registerFetch({
156+
iframely_options?.registerFetch({
157157
source: 'api',
158158
url: options.uri
159159
});
@@ -171,7 +171,7 @@ export default function(options, iframely_options, callback) {
171171
}
172172

173173
// Ignore proxy.cache_ttl, if options.cache_ttl === 0 - do not read from cache.
174-
if (iframely_options.cache_ttl === 0) {
174+
if (iframely_options?.cache_ttl === 0) {
175175

176176
if (useCacheOnly) {
177177

@@ -197,7 +197,7 @@ export default function(options, iframely_options, callback) {
197197
}
198198
}
199199

200-
iframely_options.registerFetch({
200+
iframely_options?.registerFetch({
201201
source: 'cache',
202202
url: options.uri
203203
});

0 commit comments

Comments
 (0)