1
0
forked from PGL/Clyde

adding toast on requests

This commit is contained in:
Debucquoy Anthony 2024-03-05 14:25:04 +01:00
parent d1b4023d92
commit 56a14a3e8a
Signed by: tonitch
GPG Key ID: A78D6421F083D42E
2 changed files with 11 additions and 3 deletions

View File

@ -1,4 +1,5 @@
import './assets/main.css'
import 'vue3-toastify/dist/index.css';
import { createApp } from 'vue'
import App from './Login.vue'

View File

@ -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 );
}