2022-02-24 00:04:45 +00:00
|
|
|
import { Plugin } from "@nuxt/types";
|
2021-10-09 21:08:23 +00:00
|
|
|
import { NuxtAxiosInstance } from "@nuxtjs/axios";
|
|
|
|
import { alert } from "~/composables/use-toast";
|
|
|
|
|
2022-01-09 06:15:23 +00:00
|
|
|
const toastPlugin: Plugin = ({ $axios }: { $axios: NuxtAxiosInstance }) => {
|
2021-10-09 21:08:23 +00:00
|
|
|
$axios.onResponse((response) => {
|
2022-02-24 00:04:45 +00:00
|
|
|
if (response?.data?.message) {
|
2021-10-09 21:08:23 +00:00
|
|
|
alert.info(response.data.message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$axios.onError((error) => {
|
|
|
|
if (error.response?.data?.detail?.message) {
|
|
|
|
alert.error(error.response.data.detail.message);
|
|
|
|
}
|
|
|
|
});
|
2022-02-24 00:04:45 +00:00
|
|
|
};
|
2022-01-09 06:15:23 +00:00
|
|
|
|
|
|
|
export default toastPlugin;
|