Tech review changes
This commit is contained in:
parent
dae9620843
commit
800f22ac90
2 changed files with 32 additions and 14 deletions
11
src/constants/axios-response-interceptor-messages.js
Normal file
11
src/constants/axios-response-interceptor-messages.js
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
const axiosResponseInterceptorMessages = {
|
||||||
|
NETWORK_ERROR:
|
||||||
|
"A network error occurred. " +
|
||||||
|
"This could be a bad URL, a CORS issue, or a dropped internet connection. " +
|
||||||
|
"It is impossible for us to know.",
|
||||||
|
STATUS_CODE_ERROR: "Status Code Error",
|
||||||
|
NO_RESPONSE_ERROR: "The request was made but no response was received",
|
||||||
|
GENERIC_ERROR: "Error",
|
||||||
|
};
|
||||||
|
|
||||||
|
export default axiosResponseInterceptorMessages;
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import analyticsMixIn from "@/mixins/analytics-mixin.js";
|
import analyticsMixIn from "@/mixins/analytics-mixin.js";
|
||||||
|
import router from "@/router";
|
||||||
import store from "@/store";
|
import store from "@/store";
|
||||||
|
|
||||||
import { applicationConfig } from "@/constants/application-config.js";
|
import { applicationConfig } from "@/constants/application-config.js";
|
||||||
import { GaCategories, GaActions, GaLabels } from "@/constants/analytics";
|
import { GaCategories, GaActions, GaLabels } from "@/constants/analytics";
|
||||||
import { headerKeys } from "@/constants/header-keys";
|
import { headerKeys } from "@/constants/header-keys";
|
||||||
|
import axiosResponseInterceptorMessages from "@/constants/axios-response-interceptor-messages.js";
|
||||||
|
|
||||||
// Add a response interceptor for global axios error handing.
|
// Add a response interceptor for global axios error handing.
|
||||||
axios.interceptors.response.use(
|
axios.interceptors.response.use(
|
||||||
|
|
@ -12,34 +14,31 @@ axios.interceptors.response.use(
|
||||||
(error) => {
|
(error) => {
|
||||||
let rejectionError = "";
|
let rejectionError = "";
|
||||||
if (typeof error.response === "undefined") {
|
if (typeof error.response === "undefined") {
|
||||||
// The request was not made, could be a bad connection or a CORS error.
|
// The request was not made, could be a bad url, bad connection, or a CORS error.
|
||||||
rejectionError = {
|
rejectionError = {
|
||||||
message:
|
response: error,
|
||||||
"A network error occurred. " +
|
message: axiosResponseInterceptorMessages.NETWORK_ERROR,
|
||||||
"This could be a CORS issue or a dropped internet connection. " +
|
|
||||||
"It is impossible for us to know.",
|
|
||||||
cause: error,
|
|
||||||
};
|
};
|
||||||
} else if (error.response) {
|
} else if (error.response) {
|
||||||
// The request was made and the server responded with a status code
|
// The request was made and the server responded with a status code
|
||||||
// that falls out of the range of 2xx
|
// that falls out of the range of 2xx
|
||||||
rejectionError = {
|
rejectionError = {
|
||||||
message: "Status Code Error",
|
response: error.response,
|
||||||
cause: error.response,
|
message: axiosResponseInterceptorMessages.STATUS_CODE_ERROR,
|
||||||
};
|
};
|
||||||
} else if (error.request) {
|
} else if (error.request) {
|
||||||
// The request was made but no response was received
|
// The request was made but no response was received
|
||||||
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
||||||
// http.ClientRequest in node.js
|
// http.ClientRequest in node.js
|
||||||
rejectionError = {
|
rejectionError = {
|
||||||
message: "The request was made but no response was received",
|
response: error.request,
|
||||||
cause: error.request,
|
message: axiosResponseInterceptorMessages.NO_RESPONSE_ERROR,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
// Something happened in setting up the request that triggered an Error
|
// Something happened in setting up the request that triggered an Error
|
||||||
rejectionError = {
|
rejectionError = {
|
||||||
message: "Error",
|
response: error.message,
|
||||||
cause: error.message,
|
message: axiosResponseInterceptorMessages.GENERIC_ERROR,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,9 +98,17 @@ export default {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
global.$logger.logError(`${method}: ${endpoint}: ${error.message}`, error);
|
// Do not route to error logic when no wipers found or no promo found (404s)
|
||||||
|
if (error.response.status != "404") {
|
||||||
|
router.navigateError();
|
||||||
|
}
|
||||||
|
|
||||||
return reject(error);
|
global.$logger.logError(
|
||||||
|
`${method}: ${endpoint}: ${error.message}`,
|
||||||
|
error.response
|
||||||
|
);
|
||||||
|
|
||||||
|
return reject(error.response);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue