From 56a14a3e8a36e4394d79a6aa05fa2e8f00da361c Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Tue, 5 Mar 2024 14:25:04 +0100 Subject: [PATCH] adding toast on requests --- frontend/src/login.js | 1 + frontend/src/rest/restConsumer.js | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/frontend/src/login.js b/frontend/src/login.js index 3ca2456..5e4180d 100644 --- a/frontend/src/login.js +++ b/frontend/src/login.js @@ -1,4 +1,5 @@ import './assets/main.css' +import 'vue3-toastify/dist/index.css'; import { createApp } from 'vue' import App from './Login.vue' diff --git a/frontend/src/rest/restConsumer.js b/frontend/src/rest/restConsumer.js index 4632b5f..2c240c6 100644 --- a/frontend/src/rest/restConsumer.js +++ b/frontend/src/rest/restConsumer.js @@ -1,4 +1,5 @@ import { getCookie } from '../utils.js' +import { toast } from 'vue3-toastify' const restURL = import.meta.env.PROD ? "https://clyde.herisson.ovh/api" : "http://localhost:8080" @@ -28,7 +29,13 @@ async function _rest(endPoint, config){ let session_token = getCookie("session_token"); let headers = new Headers({'Authorization': session_token}); config['headers'] = headers; - return fetch(restURL + endPoint, config).then( e => e.json()); - - // TODO: Handle errors + return toast.promise(fetch(restURL + endPoint, config), + { + pending: config['pending'] != null ? config['pending'] : 'pending', + error: config['error'] != null ? config['error'] : 'Network Failure...', + success: config['success'] != null ? config['success'] : {render(res){ + return res.ok ? "Success" : "error"; + }}, + }) + .then( e => e.json()).catch( e => e ); }