Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
include:
- os: windows-latest
artifactName: activelogin-authentication-nuget-windows
- os: macos-latest
- os: macos-15-intel
artifactName: activelogin-authentication-nuget-macos
- os: ubuntu-latest
artifactName: activelogin-authentication-nuget-ubuntu
Expand Down Expand Up @@ -87,7 +87,7 @@ jobs:
include:
- os: windows-latest
artifactName: activelogin-authentication-samples-windows
- os: macos-latest
- os: macos-15-intel
artifactName: activelogin-authentication-samples-macos
- os: ubuntu-latest
artifactName: activelogin-authentication-samples-ubuntu
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
matrix:
include:
- os: windows-latest
- os: macos-latest
- os: macos-15-intel
- os: ubuntu-latest

steps:
Expand Down
6 changes: 0 additions & 6 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ stages:
Windows:
vmImage: 'windows-latest'
artifactName: 'nuget-windows'
macOS:
vmImage: 'macOS-latest'
artifactName: 'nuget-macos'
Linux:
vmImage: 'ubuntu-latest'
artifactName: 'nuget-linux'
Expand Down Expand Up @@ -99,9 +96,6 @@ stages:
Windows:
vmImage: 'windows-latest'
artifactName: 'samples-windows'
macOS:
vmImage: 'macOS-latest'
artifactName: 'samples-macos'
Linux:
vmImage: 'ubuntu-latest'
artifactName: 'samples-linux'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ function activeloginInit(configuration: IBankIdUiScriptConfiguration, initState:
const fetchRetryCountDefault: number = 3;
const fetchRetryDelayMs: number = 1000;

const retryOnHttpErrors = {
initialize: true,
status: false, // A second call to the BankID collect endpoint is not supported after a status complete or failed is returned.
qr: true,
cancel: true
};

// Pre check

const requiredFeatures = [window.fetch, window.sessionStorage];
Expand Down Expand Up @@ -123,7 +130,7 @@ function activeloginInit(configuration: IBankIdUiScriptConfiguration, initState:
requestVerificationToken,
{
"returnUrl": returnUrl
}, fetchRetryCountDefault)
}, fetchRetryCountDefault, retryOnHttpErrors.initialize)
.then(data => {
if (data.isAutoLaunch) {
if (!data.checkStatus) {
Expand Down Expand Up @@ -177,7 +184,9 @@ function activeloginInit(configuration: IBankIdUiScriptConfiguration, initState:
"orderRef": orderRef,
"returnUrl": returnUrl,
"autoStartAttempts": autoStartAttempts
}, fetchRetryCountDefault)
},
fetchRetryCountDefault,
retryOnHttpErrors.status)
.then(data => {
if (data.retryLogin) {
autoStartAttempts++;
Expand Down Expand Up @@ -227,7 +236,7 @@ function activeloginInit(configuration: IBankIdUiScriptConfiguration, initState:
requestVerificationToken,
{
"qrStartState": qrStartState
}, fetchRetryCountDefault)
}, fetchRetryCountDefault, retryOnHttpErrors.qr)
.then(data => {
if (!!data.qrCodeAsBase64) {
qrLastRefreshTimestamp = new Date();
Expand Down Expand Up @@ -278,7 +287,13 @@ function activeloginInit(configuration: IBankIdUiScriptConfiguration, initState:

// Helpers

function postJson(url: string, requestVerificationToken: string, data: any, retryCount: number = 0): Promise<any> {
function postJson(url: string, requestVerificationToken: string, data: any, remaingRetryCount: number = 0, retryOnHttpError: boolean = true): Promise<any> {

const retry = () => {
return delay(fetchRetryDelayMs)
.then(() => postJson(url, requestVerificationToken, data, remaingRetryCount - 1, retryOnHttpError));
};

return fetch(url,
{
method: "POST",
Expand All @@ -290,22 +305,10 @@ function activeloginInit(configuration: IBankIdUiScriptConfiguration, initState:
credentials: 'include',
body: JSON.stringify(data)
})
.catch(error => {
if (retryCount > 0) {
return delay(fetchRetryDelayMs).then(() => {
return postJson(url, requestVerificationToken, data, retryCount - 1);
});
}

throw error;
})
.then(response => {
if (!response.ok && retryCount > 0) {
return delay(fetchRetryDelayMs).then(() => {
return postJson(url, requestVerificationToken, data, retryCount - 1)
});
if (!response.ok && retryOnHttpError && remaingRetryCount > 0) {
return retry();
}

return response;
})
.then(response => {
Expand All @@ -321,6 +324,25 @@ function activeloginInit(configuration: IBankIdUiScriptConfiguration, initState:
throw Error(data.errorMessage);
}
return data;
})
.catch(error => {
// A TypeError here means fetch failed before receiving any HTTP response
// (network down, DNS error, CORS block, connection aborted, etc.).
// These failures are transient and safe to retry.
const isNetworkError = error instanceof TypeError;

// Other error types should NOT be retried here:
// - HTTP-level failures (e.g., non-2xx status codes) are already handled in the
// previous `.then` block, where retry behavior is controlled by `retryOnHttpError`.
// - Any error thrown after that stage represents a *valid server response*,
// meaning the request reached the API and should not be repeated.
// Retrying such cases here could cause duplicated API calls or break BankID flows
// (e.g.collect/status), which do not allow repeated calls after a completed/failed state.
if (isNetworkError && remaingRetryCount > 0) {
return retry();
}

throw error;
});
}

Expand Down
Loading