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 { ...@@ -8,13 +8,17 @@ class APIService {
return this.isTokenValid(); 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()) { if (!APIService.isAuthenticated()) {
return Promise.reject(new Error("Your are not autenticated")); return Promise.reject(new Error("Your are not autenticated"));
} }
const response = await fetch("/api/v1/" + input, init); return new Promise((resolve, reject) => {
return await response.json(); 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