i'm using vue-resource
fetch data server. user needs have jwt token correct data. if token invalid or expired, 401 status returned. if user tries access forbidden page, 403 returned.
i catch errors , handle them appropriately (globally). means, calls should handled interceptor (if 401, 403).
how can prevent browser message "uncaught (in promise)" , create global error handling? don't want have local error handler on every call.
i have following interceptor:
vue.http.interceptors.push(function (request, next) { request.headers.set('authorization', auth.getauthheader()); next(function (response) { if (response.status === 401 || response.status === 403) { console.log('you not logged in or not have rights access site.'); } }); });
and following call in vue methods
:
methods: { user: function () { this.$http.get('http://localhost:8080/auth/user').then(function (response) { console.log(response); }); } }
Comments
Post a Comment