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 analyticsMixIn from "@/mixins/analytics-mixin.js";
|
||||
import router from "@/router";
|
||||
import store from "@/store";
|
||||
|
||||
import { applicationConfig } from "@/constants/application-config.js";
|
||||
import { GaCategories, GaActions, GaLabels } from "@/constants/analytics";
|
||||
import { headerKeys } from "@/constants/header-keys";
|
||||
import axiosResponseInterceptorMessages from "@/constants/axios-response-interceptor-messages.js";
|
||||
|
||||
// Add a response interceptor for global axios error handing.
|
||||
axios.interceptors.response.use(
|
||||
|
|
@ -12,34 +14,31 @@ axios.interceptors.response.use(
|
|||
(error) => {
|
||||
let rejectionError = "";
|
||||
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 = {
|
||||
message:
|
||||
"A network error occurred. " +
|
||||
"This could be a CORS issue or a dropped internet connection. " +
|
||||
"It is impossible for us to know.",
|
||||
cause: error,
|
||||
response: error,
|
||||
message: axiosResponseInterceptorMessages.NETWORK_ERROR,
|
||||
};
|
||||
} else if (error.response) {
|
||||
// The request was made and the server responded with a status code
|
||||
// that falls out of the range of 2xx
|
||||
rejectionError = {
|
||||
message: "Status Code Error",
|
||||
cause: error.response,
|
||||
response: error.response,
|
||||
message: axiosResponseInterceptorMessages.STATUS_CODE_ERROR,
|
||||
};
|
||||
} else if (error.request) {
|
||||
// The request was made but no response was received
|
||||
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
||||
// http.ClientRequest in node.js
|
||||
rejectionError = {
|
||||
message: "The request was made but no response was received",
|
||||
cause: error.request,
|
||||
response: error.request,
|
||||
message: axiosResponseInterceptorMessages.NO_RESPONSE_ERROR,
|
||||
};
|
||||
} else {
|
||||
// Something happened in setting up the request that triggered an Error
|
||||
rejectionError = {
|
||||
message: "Error",
|
||||
cause: error.message,
|
||||
response: 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