diff options
author | dizzy <diosmosis@users.noreply.github.com> | 2022-04-11 19:58:22 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-11 19:58:22 +0300 |
commit | 5d8f340a1f114f76d246660710cee113c735540f (patch) | |
tree | aaa73eac9cbc09d5994bc40c30e2ff070e31955e /plugins/CoreHome/vue/src | |
parent | 5531607b5d17ab67957eb4ab092f5cd20232fc07 (diff) |
[Vue] add piwik-api.js error handling logic to AjaxHelper.fetch if createErrorNotification is set to falseā¦ (#19071)
* add piwik-api.js error handling logic to AjaxHelper.fetch if createErrorNotification is set to false and do not call AjaxHelper errorCallback in this case too
* undo submodule change
Diffstat (limited to 'plugins/CoreHome/vue/src')
-rw-r--r-- | plugins/CoreHome/vue/src/AjaxHelper/AjaxHelper.ts | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/plugins/CoreHome/vue/src/AjaxHelper/AjaxHelper.ts b/plugins/CoreHome/vue/src/AjaxHelper/AjaxHelper.ts index 543754b0cd..610ede1863 100644 --- a/plugins/CoreHome/vue/src/AjaxHelper/AjaxHelper.ts +++ b/plugins/CoreHome/vue/src/AjaxHelper/AjaxHelper.ts @@ -117,7 +117,7 @@ export default class AjaxHelper<T = any> { // eslint-disable-line * * @deprecated use the jquery promise API */ - errorCallback: AnyFunction; + errorCallback: AnyFunction|null; withToken = false; @@ -220,10 +220,13 @@ export default class AjaxHelper<T = any> { // eslint-disable-line helper.headers = options.headers; } + let createErrorNotification = true; if (typeof options.createErrorNotification !== 'undefined' && !options.createErrorNotification ) { helper.useCallbackInCaseOfError(); + helper.setErrorCallback(null); + createErrorNotification = false; } if (options.abortController) { @@ -243,6 +246,16 @@ export default class AjaxHelper<T = any> { // eslint-disable-line } return result as R; + }).catch((xhr: jqXHR) => { + if (createErrorNotification) { + throw xhr; + } + + let message = 'Something went wrong'; + if (xhr.status === 504) { + message = 'Request was prossibly aborted'; + } + throw new Error(message); }); } @@ -364,7 +377,7 @@ export default class AjaxHelper<T = any> { // eslint-disable-line * * @deprecated use the jquery promise API */ - setErrorCallback(callback: AnyFunction): void { + setErrorCallback(callback: AnyFunction|null): void { this.errorCallback = callback; } @@ -477,11 +490,13 @@ export default class AjaxHelper<T = any> { // eslint-disable-line resolve(data as (T | ErrorResponse)); // ignoring textStatus/jqXHR } }).fail((xhr: jqXHR) => { - if (xhr.statusText !== 'abort') { - console.log(`Warning: the ${$.param(this.getParams)} request failed!`); - - reject(xhr); + if (xhr.statusText === 'abort') { + return; } + + console.log(`Warning: the ${$.param(this.getParams)} request failed!`); + + reject(xhr); }).done(() => { if ($timeout) { $timeout(); // trigger digest |