ApiQuery.js

33 lines | 854 B Blame History Raw Download

import Log from './LogTools'
import Notification from './Notification'


//Обертка для запросов к базе
//URL - 
//Methid : Get Post
//data: данные
export default function ApiQuery(url, method, data) {
    Log("ApiQuery", "query to " + url);
    //let json = JSON.stringify(data);
    //debugger;
    return fetch(
        url,
        {
            method: method,
            headers: {
                'Content-Type': 'application/json'
            },
            credentials: 'include',
            body: JSON.stringify(data)
        }
    ).then(function (response) {
        return response.json();
    }).catch(
        //Ошибка при выполнении запроса к беку
        function () {
            Notification.MesEr("Api query error", "ApiQuery");
            throw "";
        }
    );
}