Comments (3)
Right now up.replace
will always swap a page fragement into up-target
, up-fail-target
or the first matching selector from up.config.fallbacks
.
You cannot prevent this with catch
or promise rejection handlers. The rejection handler will be called after up-fail-target
was replaced with a non-200 response.
In a future version there might be a way to customize the handling of error responses. Currently the server is expected to always deliver a controlled response.
from unpoly.
update: i've wrapped my up.replace
call in a try/catch block, and that seems to suffice for now
let options = {
transition: 'none',
history: false, // don't update url by default
//failTarget: '.overlay-error-container', //default 'body'
//fallback: '.overlay-error-container'
failLayer: 'invisible-layer' // <- SWEEP NON-200s under the rug
};
if(do_update_url){
options.history = next_history_url;
options.historyMethod = 'replace';
}
return new Promise((resolve, reject)=>{
try {
up.replace('#search-results-overlay .inner', load_url, options)
.then(()=>{
resolve(); // resolve outer
})
// normalize outer promise to native Promise .catch
// instead of Jquery Deferred .fail
.fail(()=>{
reject(); // reject outer
// SHOW FRIENDLY ERROR, JS FAILS TO REACH THIS BIT
$('#search-results-overlay .note.error').show();
})
.always(()=>{
this.overlay_fetching_results = false;
});
}catch(e){
reject();
// SHOW FRIENDLY ERROR, THIS WORKS!
$('#search-results-overlay .note.error').show();
}
});
from unpoly.
another update: i was mistaken... try/catch
did work to show friendly error message, but failLayer: 'bogus-layer-name'
breaks up.replace
entirely. :<
tried setting up.dom.config.fallbacks = ['.overlay-error-container'];
same error though.
-
is there some way i can offload the contents of XHR.body -> into some hidden dom element on the current page?
-
or just override/disable/prevent the default failTarget/failLayer behaviour entirely?
-
maybe the proper unpoly way to solve this would be a server-side try/catch and just always returning 200s & server-rendered friendly error message, when, for example, my search server is overloaded, however I can't always guarantee control of the server response status code at server-application level, and there may still be extreme error examples where I'd still rather not blow away the entire page body due to a server hiccup
from unpoly.
Related Issues (20)
- up.compiler batch throwing error HOT 1
- Allow ignoring the query parameters (search) for current links in navigation feedback HOT 2
- `a[up-accept-location]` Attribute Not Working HOT 4
- Unpoly 3.0.0-rc2 tries to re-register `up.on()` on browser back button HOT 2
- TypeError: Cannot read properties of undefined (reading 'isConnected') HOT 4
- unpoly-migrate throws error when resolving origin of URL target with query parameters and square brackets HOT 1
- Feature: [up-validate] with different URL HOT 3
- up-validate on input[type=date] with flatpicker not working since 3.x HOT 5
- up-href in table row (tr) not working HOT 1
- event.location from `up:location:changed` is not string when using browser back/forward HOT 2
- "Failed to execute 'querySelectorAll'" when selector contains special characters HOT 5
- CSP blocking `up.reload` even with `unsafe-eval` HOT 4
- Submit via out-of-form element does not contribute the element name/value pair HOT 2
- DOMException: Failed to execute 'matches' on 'Element': ':none' is not a valid selector. HOT 3
- While in an overlay, Unpoly 3 injects a form fragment outside [up-target] after onBlur validation HOT 6
- Cannot submit form containing a field called "contains" in Unpoly 3 HOT 3
- Allow custom navigation feedback HOT 7
- Redirect to new URL
- Wrong cursor position on up-autosubmit form with field type="number" HOT 1
- Using up.on with the passive option set to true raises an unexpected error HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unpoly.