File tree Expand file tree Collapse file tree 2 files changed +12
-20
lines changed Expand file tree Collapse file tree 2 files changed +12
-20
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ planned for 2025-07-01
38
38
- Removed as many of the date conversions as possible
39
39
- Use ` moment-timezone ` when calculating recurring events, this will fix problems from the past with offsets and DST not being handled properly
40
40
- Added some tests to test the behavior of the refactored methods to make sure the correct event dates are returned
41
+ - [ refactor] Simplify the ` loadJSON ` function in ` translator.js ` by replacing ` XMLHttpRequest ` with ` fetch ` (#3792 )
41
42
42
43
### Fixed
43
44
Original file line number Diff line number Diff line change 3
3
const Translator = ( function ( ) {
4
4
5
5
/**
6
- * Load a JSON file via XHR .
6
+ * Load a JSON file using fetch .
7
7
* @param {string } file Path of the file we want to load.
8
8
* @returns {Promise<object> } the translations in the specified file
9
9
*/
10
10
async function loadJSON ( file ) {
11
- const xhr = new XMLHttpRequest ( ) ;
12
- return new Promise ( function ( resolve ) {
13
- xhr . overrideMimeType ( "application/json" ) ;
14
- xhr . open ( "GET" , file , true ) ;
15
- xhr . onreadystatechange = function ( ) {
16
- if ( xhr . readyState === 4 && xhr . status === 200 ) {
17
- // needs error handler try/catch at least
18
- let fileInfo = null ;
19
- try {
20
- fileInfo = JSON . parse ( xhr . responseText ) ;
21
- } catch ( exception ) {
22
- // nothing here, but don't die
23
- Log . error ( ` loading json file =${ file } failed` ) ;
24
- }
25
- resolve ( fileInfo ) ;
26
- }
27
- } ;
28
- xhr . send ( null ) ;
29
- } ) ;
11
+ try {
12
+ const response = await fetch ( file ) ;
13
+ if ( ! response . ok ) {
14
+ throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
15
+ }
16
+ return await response . json ( ) ;
17
+ } catch ( error ) {
18
+ Log . error ( `Loading json file ${ file } failed: ${ error . message } ` ) ;
19
+ return null ;
20
+ }
30
21
}
31
22
32
23
return {
You can’t perform that action at this time.
0 commit comments