fix wrapper

This commit is contained in:
Daria Golova
2022-06-15 14:21:39 +03:00
parent 49aff14a80
commit 3fcda54070

View File

@@ -3,7 +3,7 @@ function prepareUrl(url) {
return `/api/${url}`; return `/api/${url}`;
} }
function handleRequest(attempts = 3, method, url, body) { function handleRequest(method, url, attempts, body) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
(function internalRequest() { (function internalRequest() {
return request(method, url, body) return request(method, url, body)
@@ -44,7 +44,26 @@ function request(method, url, body) {
return fetch(url, requestOptions); return fetch(url, requestOptions);
}; };
function get(url, attempts = 1) {
return handleRequest('get', url, attempts);
}
function del(url, attempts = 1) {
return handleRequest('del', url, attempts);
}
function post(url, body, attempts = 1) {
return handleRequest('post', url, attempts, body);
}
function put(url, body, attempts = 1) {
return handleRequest('put', url, attempts, body);
}
export const fetchWrapper = { export const fetchWrapper = {
handleRequest, get,
baseUrl: '', del,
post,
put,
baseUrl: ''
}; };