Tuesday, 14 November 2023
  13 Replies
  299 Visits
  Subscribe
Greetings,
I have an occasional recurring problem when making fetch calls.
the call fails returning the following error: ERR_HTTP2_PROTOCOL_ERROR
the flow returns to operation by trying to make the call several times, or by reloading the page.
It's a very frustrating problem that I haven't been able to resolve.
I hope I can help you
I attach an example of one of my fetch calls:

function NewFetchRequest(URL, Amethod, Amode, Aredirect, Aheaders, Abody) {
Aheaders.action = 'fetchaction';
return new Request(URL, {
method: Amethod,
mode: Amode,
redirect: Aredirect,
headers: Aheaders,
body: JSON.stringify(Abody)
});
}

function checkStatus(response) {
if (response.status >= 200 && response.status < 300) {
return Promise.resolve(response);
} else {
return Promise.reject(response.status);
}
}

function parseJson(response) {
return response.json();
}

function RaiseError(codeError) {
switch (codeError) {
case 300:
window.location.href = '/';
break;
case 400:
DialogInfo('%%MissingPrivileges%%');
break;
case 500:
DialogInfo('%%UnknowError%%');
break;
default:
console.log(codeError);
}
}


let req = NewFetchRequest('GetLastOrderSeriesRequest', 'POST', 'cors', 'follow', {}, {});
fetch(req)
.then(checkStatus)
.then(parseJson)
.then(function (data) {
do something...
}).catch(function (code) {
RaiseError(code);
});