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