Skip to content
Snippets Groups Projects
Commit b51c6bfa authored by Jacopo Gasparetto's avatar Jacopo Gasparetto
Browse files

Refactor get fetch

parent e5a36f90
No related branches found
No related tags found
No related merge requests found
......@@ -8,13 +8,17 @@ class APIService {
return this.isTokenValid();
}
static async get(input: RequestInfo | URL, init?: RequestInit | undefined): Promise<any> {
static get(input: RequestInfo | URL, init?: RequestInit | undefined): Promise<any> {
if (!APIService.isAuthenticated()) {
return Promise.reject(new Error("Your are not autenticated"));
}
const response = await fetch("/api/v1/" + input, init);
return await response.json();
return new Promise((resolve, reject) => {
fetch("/api/v1/" + input, init)
.then(response => response.json())
.then(data => resolve(data))
.catch(err => reject(err));
});
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment