import axios from "axios";
import { toast } from "react-toastify";

export const wwwAPI = "/qwilight/www";

export const wwwAXIOS = axios.create({
  baseURL: wwwAPI,
  validateStatus: (status) => status < 500,
});

wwwAXIOS.interceptors.response.use(async (value) => {
  switch (value.status) {
    case 401:
      if (!value.data.isSilent) {
        toast.error("Unauthorized");
        window.sessionStorage.removeItem("totem");
        window.location.reload();
      }
      break;
    case 413:
      toast.error("Payload Too Large");
      break;
    case 502:
      toast.error("Bad Gateway");
      break;
  }

  return value;
});
