Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)


## [0.6.0] - 2025-04-04
### Added
- Retry requests on network error and on HTTP 410 Gone response send by backend, which
allows to implement more robust behavior on mobile devices (long polling requests
to status endpoints are known to fail with network error when browser is in background,
and browser does go to background when SmartID app pops up).

### Changed
- use `web-eid` instead of legacy `hwcrypto`

[0.6.0]: https://github.com/thorgate/esteid-helper/compare/0.4.0...0.6.0
22 changes: 18 additions & 4 deletions IdentificationManager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import IdCardManager from "./IdCardManager";

const request = async (url, data, method = "POST") => {
const request = async (url, data, method = "POST", retries = 3) => {
const headers = {
"Content-Type": "application/json",
};
Expand All @@ -10,9 +10,24 @@ const request = async (url, data, method = "POST") => {
headers["X-CSRFToken"] = data.csrfmiddlewaretoken;
body = JSON.stringify(data || {});
}

const onError = async (err) => {
const retriesRemaining = retries - 1;
if (retriesRemaining > 0) {
console.log(`Error fetching ${url}: ${err}, waiting for 1000ms before retrying.`);
await new Promise((resolve) => setTimeout(resolve, 1000));
console.log(`Retrying ${url}, ${retriesRemaining} tries remaining.`);
return await request(url, data, method, retriesRemaining);
}
console.log(err);
return {};
};

try {
const response = await fetch(url, { method, headers, body });

if (`${response.status}` === "410") {
return await onError(new Error("The session is gone, we need to try and refresh the page."));
}
const responseText = await response.text();

try {
Expand All @@ -28,8 +43,7 @@ const request = async (url, data, method = "POST") => {
return {};
}
} catch (err) {
console.log(err);
return {};
return await onError(err);
}
};

Expand Down
44 changes: 29 additions & 15 deletions dist/Esteid.main.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
var IdCardManager_default = IdCardManager;

// IdentificationManager.js
var request = async (url, data, method = "POST") => {
var request = async (url, data, method = "POST", retries = 3) => {
const headers = {
"Content-Type": "application/json"
};
Expand All @@ -241,24 +241,38 @@
headers["X-CSRFToken"] = data.csrfmiddlewaretoken;
body = JSON.stringify(data || {});
}
const onError = async (err) => {
const retriesRemaining = retries - 1;
if (retriesRemaining > 0) {
console.log(`Error fetching ${url}: ${err}, waiting for 1000ms before retrying.`);
await new Promise((resolve) => setTimeout(resolve, 1e3));
console.log(`Retrying ${url}, ${retriesRemaining} tries remaining.`);
return await request(url, data, method, retriesRemaining);
}
console.log(err);
return {};
};
try {
const response = await fetch(url, { method, headers, body });
const responseText = await response.text();
try {
const data2 = JSON.parse(responseText);
data2.success = data2.status === "success";
data2.pending = `${response.status}` === "202";
return {
data: data2,
ok: response.ok
};
} catch (err) {
console.log("Failed to parse response as JSON", responseText);
return {};
if (`${response.status}` !== "410") {
const responseText = await response.text();
try {
const data2 = JSON.parse(responseText);
data2.success = data2.status === "success";
data2.pending = `${response.status}` === "202";
return {
data: data2,
ok: response.ok
};
} catch (err) {
console.log("Failed to parse response as JSON", responseText);
return {};
}
} else {
return await onError(new Error("The session is gone, we need to try and refresh the page."));
}
} catch (err) {
console.log(err);
return {};
return await onError(err);
}
};
var IdentificationManager = class {
Expand Down
Loading