2022-01-09 06:15:23 +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) => {
|
|
|
|
if (response.data.message) {
|
|
|
|
alert.info(response.data.message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$axios.onError((error) => {
|
|
|
|
if (error.response?.data?.detail?.message) {
|
|
|
|
alert.error(error.response.data.detail.message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2022-01-09 06:15:23 +00:00
|
|
|
|
|
|
|
export default toastPlugin;
|