http - Responding Globally to a 401 in Polymer -


using polymer 1.0, looking best approach showing login user when app receives 401 app services.

using angular looking @ using httpinterceptor this, there equivalent in polymer?

here's approach explicitly routes errors service element (using iron-ajax)

<template is="dom-bind" id="app">     <values-service values="{{items}}" on-error="onerror"></values-service>      <h1>items <span>{{items}}</span></h1>      <template is="dom-repeat" items="{{items}}">         <p>{{item}}</p>     </template> </template>  <script src="app.js"></script> 

and app script

(function (document) {     'use strict';      var app = document.queryselector('#app');      app.onerror = function (e) {          console.log('app.onerror ' + e.detail.request.status);     };      app.addeventlistener('error', app.onerror);  })(document); 

this works, login want happen without having wire elements specifically

to solve this, created component used ajax requests. in component, listened 401s service calls, , called this.fire('401-found') when found.

then in other components, listened such event - in case, in main document, popping dialog asking user log in again.

a better approach have ajax component take in parameters 'yes fire 401 event' , 'do not give standard 401 event, name call this' in each component listen such events , react accordingly.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -