adding toast on requests
This commit is contained in:
parent
d1b4023d92
commit
56a14a3e8a
@ -1,4 +1,5 @@
|
|||||||
import './assets/main.css'
|
import './assets/main.css'
|
||||||
|
import 'vue3-toastify/dist/index.css';
|
||||||
|
|
||||||
import { createApp } from 'vue'
|
import { createApp } from 'vue'
|
||||||
import App from './Login.vue'
|
import App from './Login.vue'
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { getCookie } from '../utils.js'
|
import { getCookie } from '../utils.js'
|
||||||
|
import { toast } from 'vue3-toastify'
|
||||||
|
|
||||||
const restURL = import.meta.env.PROD ? "https://clyde.herisson.ovh/api" : "http://localhost:8080"
|
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 session_token = getCookie("session_token");
|
||||||
let headers = new Headers({'Authorization': session_token});
|
let headers = new Headers({'Authorization': session_token});
|
||||||
config['headers'] = headers;
|
config['headers'] = headers;
|
||||||
return fetch(restURL + endPoint, config).then( e => e.json());
|
return toast.promise(fetch(restURL + endPoint, config),
|
||||||
|
{
|
||||||
// TODO: Handle errors
|
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 );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user