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

export const wwwAPIPath = "/qwilight/www";

export const wwwAPI = axios.create({
  baseURL: wwwAPIPath,
});

wwwAPI.interceptors.response.use(
  (value) => value,
  (e: AxiosError) => {
    switch (e.response?.status) {
      case 401:
        toast.error("Unauthorized");
        window.sessionStorage.removeItem("totem");
        break;
      case 502:
        toast.error("Bad Gateway");
        break;
    }

    throw e;
  },
);
