Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4091494
fetch.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
fetch.js
View Options
/*
* Adapted from Vector
* All credits go to the developers behind Vector
* @see https://github.com/wikimedia/mediawiki-skins-Vector/blob/master/resources/skins.vector.search/fetch.js
*/
/**
* @typedef {Object} AbortableFetch
* @property {Promise<any>} fetch
* @property {Function} abort
*/
/**
* @typedef {Object} NullableAbortController
* @property {AbortSignal | undefined} signal
* @property {Function} abort
*/
const
nullAbortController
=
{
signal
:
undefined
,
abort
:
()
=>
{}
// Do nothing (no-op)
};
/**
* A wrapper which combines native fetch() in browsers and the following json() call.
*
* @param {string} resource
* @param {RequestInit} [init]
* @return {AbortableFetch}
*/
function
fetchJson
(
resource
,
init
)
{
// As of 2020, browser support for AbortController is limited:
// https://caniuse.com/abortcontroller
// so replacing it with no-op if it doesn't exist.
const
controller
=
window
.
AbortController
?
new
AbortController
()
:
nullAbortController
;
const
getJson
=
fetch
(
resource
,
Object
.
assign
(
{},
init
,
{
signal
:
controller
.
signal
}
)
).
then
(
(
response
)
=>
{
if
(
!
response
.
ok
)
{
throw
new
Error
(
'Network request failed with HTTP code '
+
response
.
status
);
}
return
response
.
json
();
}
);
return
{
fetch
:
getJson
,
abort
:
()
=>
{
controller
.
abort
();
}
};
}
module
.
exports
=
fetchJson
;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Aug 18 2026, 11:45 (5 w, 1 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
a4/11/cf3921b36b3390319fb72b46bd85
Default Alt Text
fetch.js (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment