From 3fcda5407004382abc1a462d44ecfe156ad154d7 Mon Sep 17 00:00:00 2001 From: Daria Golova Date: Wed, 15 Jun 2022 14:21:39 +0300 Subject: [PATCH] fix wrapper --- src/shared/fetchWrapper.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/shared/fetchWrapper.js b/src/shared/fetchWrapper.js index 2cd36ad..3fff02a 100644 --- a/src/shared/fetchWrapper.js +++ b/src/shared/fetchWrapper.js @@ -3,7 +3,7 @@ function prepareUrl(url) { return `/api/${url}`; } -function handleRequest(attempts = 3, method, url, body) { +function handleRequest(method, url, attempts, body) { return new Promise((resolve, reject) => { (function internalRequest() { return request(method, url, body) @@ -44,7 +44,26 @@ function request(method, url, body) { 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 = { - handleRequest, - baseUrl: '', + get, + del, + post, + put, + baseUrl: '' }; \ No newline at end of file