adding toast on requests
This commit is contained in:
		| @ -1,4 +1,5 @@ | ||||
| import './assets/main.css' | ||||
| import 'vue3-toastify/dist/index.css'; | ||||
|  | ||||
| import { createApp } from '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" | ||||
|  | ||||
| @ -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 ); | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user