From 373bd9b962ce50af6d938b9cb68d090f95c88704 Mon Sep 17 00:00:00 2001 From: Domingos Panta Date: Wed, 11 May 2022 17:56:31 +0100 Subject: [PATCH] Added response interceptor to axios response. This interceptor checks for response code 404 and redicts the user if that is the case. --- src/mixins/public.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/mixins/public.js b/src/mixins/public.js index a3e12f460..16b60129b 100644 --- a/src/mixins/public.js +++ b/src/mixins/public.js @@ -7,6 +7,17 @@ if (env === "development" || localStorage.dev === "dev") { axios.defaults.baseURL = location.protocol + "//" + location.hostname + ":3001"; } +// Add a response interceptor to catch 404 errors in dymanic routes such as /status/:slug +axios.interceptors.response.use(function (response) { + return response; +}, function (error) { + if(error.response.status === 404){ + location.href = "/page-not-found"; + } + console.log(error); + return Promise.reject(error); +}); + export default { data() { return {