Path: blob/main/extensions/copilot/src/shared-fetch-utils/common/middleware/windowActiveMiddleware.ts
13401 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { FetchBlockedError, type FetchMiddleware, type WindowStateProvider } from '../fetchTypes';67export class WindowInactiveError extends FetchBlockedError {8constructor() {9super('Window is inactive', 60_000);10}11}1213/**14* Prevents fetches while the window is inactive by throwing a15* {@link WindowInactiveError}. Callers that cache the parsed value16* (e.g. {@link FetchedValue}) will fall back to the last-good value17* automatically because they handle {@link FetchBlockedError}.18*/19export function windowActiveMiddleware(provider: WindowStateProvider): FetchMiddleware {20return (next) => async (request) => {21if (!provider.isActive) {22throw new WindowInactiveError();23}24return next(request);25};26}272829