A lightweight Vue.js plugin that registers global Axios response interceptors and exposes a global event bus (window.intercepted) to catch and handle AJAX errors uniformly across the application. Version 0.3.2 (no recent releases) is designed for Vue 2 and requires Axios and Vue to be available on the window object. It emits events by status code category (e.g., 'response:4xx', 'response:500') and specific codes (e.g., 'response:404'), with special parsing for Laravel 5.5+ 422 validation errors (body becomes a key-value object). Differentiates from manual interceptors by providing a ready-made event system; minimal setup but limited to Vue 2 and global window dependencies.
npm install vue-axios-interceptorsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows setup with global Vue and Axios, then attaching listeners for all responses and specific error codes.
Use require('vue-axios-interceptors') after setting window.Vue. Do not use import or Vue.use().Ensure window.Vue = require('vue'); and window.axios = require('axios'); are executed before the require statement.Use a different error handling solution or manually adapt using a third-party event emitter for Vue 3.
Set window.axios before requiring the package and do not reassign it afterward.
Use exact event name as documented: 'response:unprocessable-entity' and expect data.body to be a key-value object for Laravel 422 errors.
Set window.Vue = require('vue'); before require('vue-axios-interceptors');Set window.axios = require('axios'); before require('vue-axios-interceptors');Install via npm: npm install vue-axios-interceptors --save. Then use require('vue-axios-interceptors') (not import). Ensure the module is in node_modules.