Skip to content

Commit

Permalink
πŸ› Don't report request cancellation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
skerit committed Jul 25, 2024
1 parent 5ebdc06 commit f51e317
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions lib/client/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,30 @@ Scene.setMethod(function fetch(href, options, callback) {
return this.general_renderer.fetch(href, options, callback);
});

/**
* Is the given error a request cancellation?
*
* @author Jelle De Loecker <[email protected]>
* @since 2.4.0
* @version 2.4.0
*
* @param {Error} err
*
* @return {boolean}
*/
function isRequestCancellationError(err) {

if (!err) {
return false;
}

if (err.status == 0 && err.number == 0) {
return true;
}

return false;
}

/**
* Browse to a link using AJAX.
* The response will be an item this client needs to render.
Expand Down Expand Up @@ -491,6 +515,7 @@ Scene.setMethod(function openUrl(href, options, callback) {
}

let error = new Error('Request has been cancelled');
error.status = error.number = 0;
pledge.reject(error);

return false;
Expand Down Expand Up @@ -3006,7 +3031,7 @@ Scene.setMethod(function detectDoubleClick(request, min_duration) {
*
* @author Jelle De Loecker <[email protected]>
* @since 2.0.0
* @version 2.3.3
* @version 2.4.0
*
* @param {HTMLElement} element
* @param {HTMLEvent} e
Expand Down Expand Up @@ -3120,6 +3145,12 @@ Scene.setMethod(function onLinkClick(element, e) {
}

if (err) {

// Ignore cancellations
if (isRequestCancellationError(err)) {
return;
}

if (typeof that.errorHandler == 'function') {
that.errorHandler(err, {type: 'openUrl', options: options, url: href});
} else {
Expand Down Expand Up @@ -3170,7 +3201,7 @@ Scene.setMethod(function markElementBusy(element, busy) {
*
* @author Jelle De Loecker <[email protected]>
* @since 2.0.0
* @version 2.3.18
* @version 2.4.0
*
* @param {HTMLElement} form
* @param {HTMLEvent} e
Expand Down Expand Up @@ -3248,6 +3279,12 @@ Scene.setMethod(function onFormSubmit(form, e, options) {
}

if (err) {

// Ignore cancellations
if (isRequestCancellationError(err)) {
return;
}

return console.error(err);
}

Expand Down

0 comments on commit f51e317

Please sign in to comment.