/// A wordless page for an error the window itself loaded: Chrome would /// otherwise paint its own "This page isn't working" sentences over an /// empty error body. Only the title carries the app's name (OS-level label). library; import 'dart:io'; /// HTML page with only an icon — no words painted by the browser. const String errorIconPage = ' ' 'Diet Guard ' ' ' ' ' ''; /// Whether [request] is the window loading a page, not the app's fetch(). bool isNavigation(HttpRequest request) => request.headers.value('sec-fetch-mode') == 'navigate'; /// Replaces an error answer to a page load with [errorIconPage]. Does /// nothing for fetch() calls, successes, or a response already written. void paintErrorIcon(HttpRequest request) { final response = request.response; if (!isNavigation(request) || response.statusCode < 400) return; try { response.headers.contentType = ContentType.html; response.write(errorIconPage); } on Exception { return; // body already sent: leave it alone } }