Giter VIP home page Giter VIP logo

Comments (3)

triskweline avatar triskweline commented on May 24, 2024 1

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.

jakedowns avatar jakedowns commented on May 24, 2024

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.

jakedowns avatar jakedowns commented on May 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.