mirror of
https://github.com/vector-im/element-call.git
synced 2026-01-30 03:15:55 +00:00
fetch returns a response code of 0 when it successfully loads a `file://` resource. This means we can't just rely on `response.ok`. Required for https://github.com/element-hq/element-call/issues/2994
26 lines
718 B
TypeScript
26 lines
718 B
TypeScript
/*
|
|
Copyright 2025 New Vector Ltd.
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
Please see LICENSE in the repository root for full details.
|
|
*/
|
|
|
|
/**
|
|
* Check if a fetch response is a failure in a way that works with file:// URLs
|
|
* @param response the response to check
|
|
* @returns true if the response is a failure, false otherwise
|
|
*/
|
|
export function isFailure(response: Response): boolean {
|
|
// if response says it's okay, then it's not a failure
|
|
if (response.ok) {
|
|
return false;
|
|
}
|
|
|
|
// fetch will return status === 0 for a success on a file:// URL, so we special case it
|
|
if (response.url.startsWith("file:") && response.status === 0) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|