1
0
mirror of https://github.com/SomboChea/ui synced 2026-01-17 08:35:47 +07:00

chore: first try to download files with fetch

This commit is contained in:
Juan Picado @jotadeveloper
2019-07-28 10:25:22 +02:00
parent fd74c52bd1
commit 9d006ad6f7
2 changed files with 47 additions and 12 deletions

View File

@@ -25,7 +25,7 @@ function handleResponseType(response: Response): Promise<[boolean, Blob | string
}
class API {
public request<T>(url: string, method = 'GET', options: RequestInit = { headers: {} }): Promise<T> {
public request<T>(url: string, method = 'GET', options: RequestInit = { headers: {} }, isFile: boolean = false): Promise<T> {
if (!window.VERDACCIO_API_URL) {
throw new Error('VERDACCIO_API_URL is not defined!');
}
@@ -50,11 +50,11 @@ class API {
})
// @ts-ignore
.then(handleResponseType)
.then(([responseOk, body]) => {
if (responseOk) {
resolve(body);
.then(response => {
if (response[0]) {
resolve(response[1]);
} else {
reject(body);
reject(new Error('something went wrong'));
}
})
.catch(error => {