Improve Blazor WASM error handling and bump version
Enhanced error handling in Blazor WebAssembly startup: - Added `getErrorText` to extract error messages. - Introduced `isWasmStartupFailure` for WASM-specific errors. - Updated `showStartupFallback` to prevent duplicate execution. - Refined event listeners for `unhandledrejection` and `error`. - Removed unused `started` variable. Updated `EnvelopeGenerator.Server.csproj` version numbers: - `Version` to 1.12.0-beta. - `FileVersion` to 1.12.0.0. - `AssemblyVersion` to 1.12.0.0.
This commit is contained in:
@@ -52,9 +52,42 @@
|
|||||||
<script src="_framework/blazor.web.js" autostart="false"></script>
|
<script src="_framework/blazor.web.js" autostart="false"></script>
|
||||||
<script>
|
<script>
|
||||||
(function () {
|
(function () {
|
||||||
var started = false;
|
var fallbackShown = false;
|
||||||
|
|
||||||
|
function getErrorText(reason) {
|
||||||
|
if (!reason) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof reason === 'string') {
|
||||||
|
return reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reason && typeof reason.message === 'string') {
|
||||||
|
return reason.message;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return JSON.stringify(reason);
|
||||||
|
} catch {
|
||||||
|
return String(reason);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function isWasmStartupFailure(reason) {
|
||||||
|
var text = getErrorText(reason).toLowerCase();
|
||||||
|
return text.indexOf('wasm simd') >= 0 ||
|
||||||
|
text.indexOf('failed to start platform') >= 0 ||
|
||||||
|
text.indexOf('instantiate_wasm_module') >= 0 ||
|
||||||
|
text.indexOf('mono_download_assets') >= 0 ||
|
||||||
|
text.indexOf('/_framework/dotnet') >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
function showStartupFallback(reason) {
|
function showStartupFallback(reason) {
|
||||||
|
if (fallbackShown) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var root = document.getElementById('sf-client-startup-fallback');
|
var root = document.getElementById('sf-client-startup-fallback');
|
||||||
if (!root) {
|
if (!root) {
|
||||||
return;
|
return;
|
||||||
@@ -64,6 +97,8 @@
|
|||||||
console.error('Blazor startup failed:', reason);
|
console.error('Blazor startup failed:', reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fallbackShown = true;
|
||||||
|
root.removeAttribute('hidden');
|
||||||
root.hidden = false;
|
root.hidden = false;
|
||||||
root.style.display = 'flex';
|
root.style.display = 'flex';
|
||||||
}
|
}
|
||||||
@@ -74,21 +109,20 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('unhandledrejection', function (event) {
|
window.addEventListener('unhandledrejection', function (event) {
|
||||||
if (!started) {
|
if (isWasmStartupFailure(event.reason)) {
|
||||||
showStartupFallback(event.reason);
|
showStartupFallback(event.reason);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener('error', function (event) {
|
window.addEventListener('error', function (event) {
|
||||||
if (!started) {
|
var reason = event.error || event.message;
|
||||||
showStartupFallback(event.error || event.message);
|
if (isWasmStartupFailure(reason)) {
|
||||||
|
showStartupFallback(reason);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
window.Blazor.start({
|
window.Blazor.start({
|
||||||
webAssembly: {}
|
webAssembly: {}
|
||||||
}).then(function () {
|
|
||||||
started = true;
|
|
||||||
}).catch(function (error) {
|
}).catch(function (error) {
|
||||||
showStartupFallback(error);
|
showStartupFallback(error);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,9 +10,9 @@
|
|||||||
<Authors>Digital Data GmbH</Authors>
|
<Authors>Digital Data GmbH</Authors>
|
||||||
<Company>Digital Data GmbH</Company>
|
<Company>Digital Data GmbH</Company>
|
||||||
<Product>EnvelopeGenerator.Server</Product>
|
<Product>EnvelopeGenerator.Server</Product>
|
||||||
<Version>1.11.0-beta</Version>
|
<Version>1.12.0-beta</Version>
|
||||||
<FileVersion>1.11.0.0</FileVersion>
|
<FileVersion>1.12.0.0</FileVersion>
|
||||||
<AssemblyVersion>1.11.0.0</AssemblyVersion>
|
<AssemblyVersion>1.12.0.0</AssemblyVersion>
|
||||||
<Copyright>Copyright © 2026 Digital Data GmbH. All rights reserved.</Copyright>
|
<Copyright>Copyright © 2026 Digital Data GmbH. All rights reserved.</Copyright>
|
||||||
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
|
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user