Repository: 4ian/GDevelop
File: GDJS/Runtime/howler-sound-manager/howler-sound-manager.ts (TypeScript)

Code before:
          logger.warn(
            'There was an error while preloading an audio file: ' + error
          );
          throw error;
        }
      } else if (
        resource.preloadInCache ||
        // Force downloading of sounds.
        // TODO Decide if sounds should be allowed to be downloaded after the scene starts.
        // - they should be requested automatically at the end of the scene loading
        // - they will be downloaded while the scene is playing
        // - other scenes will be pre-loaded only when all the sounds for the current scene are in cache
        !resource.preloadAsMusic
      ) {
        // preloading as sound already does a XHR request, hence "else if"
        try {
          const file = resource.file;
          await new Promise((resolve, reject) => {
            const sound = new XMLHttpRequest();
            sound.withCredentials =
              this._resourceLoader.checkIfCredentialsRequired(file);
            sound.addEventListener('load', () => {
              if (sound.status >= 200 && sound.status < 300) {
                resolve(undefined);
              } else {
                reject(`HTTP error! status: ${sound.status}`);
              }
            });
            sound.addEventListener('error', (_) =>
              reject('XHR error: ' + file)
            );
            sound.addEventListener('abort', (_) =>
              reject('XHR abort: ' + file)
            );
            sound.open('GET', this._getDefaultSoundUrl(resource));
            sound.send();
          });
        } catch (error) {
          delete this._availableResources[resource.name];
          logger.warn(
            'There was an error while preloading an audio file: ' + error
          );
          throw error;
        }
      }
    }

    getNetworkSyncData(): SoundManagerSyncData {
      const freeMusicsNetworkSyncData: SoundSyncData[] = [];
      this._freeMusics.forEach((freeMusic) => {
        const musicSyncData = freeMusic.getNetworkSyncData();

Review comment (bug):
I suggest an exception that gives more context to ease debugging:
```suggestion
                reject(`HTTP error while preloading audio file in cache. Status is ${sound.status}.`);
```

Code after:
          logger.warn(
            'There was an error while preloading an audio file: ' + error
          );
          throw error;
        }
      } else if (
        resource.preloadInCache ||
        // Force downloading of sounds.
        // TODO Decide if sounds should be allowed to be downloaded after the scene starts.
        // - they should be requested automatically at the end of the scene loading
        // - they will be downloaded while the scene is playing
        // - other scenes will be pre-loaded only when all the sounds for the current scene are in cache
        !resource.preloadAsMusic
      ) {
        // preloading as sound already does a XHR request, hence "else if"
        try {
          const file = resource.file;
          await new Promise((resolve, reject) => {
            const sound = new XMLHttpRequest();
            sound.withCredentials =
              this._resourceLoader.checkIfCredentialsRequired(file);
            sound.addEventListener('load', () => {
              if (sound.status >= 200 && sound.status < 300) {
                resolve(undefined);
              } else {
                reject(
                  `HTTP error while preloading audio file in cache. Status is ${sound.status}.`
                );
              }
            });
            sound.addEventListener('error', (_) =>
              reject('XHR error: ' + file)
            );
            sound.addEventListener('abort', (_) =>
              reject('XHR abort: ' + file)
            );
            sound.open('GET', this._getDefaultSoundUrl(resource));
            sound.send();
          });
        } catch (error) {
          delete this._availableResources[resource.name];
          logger.warn(
            'There was an error while preloading an audio file: ' + error
          );
          throw error;
        }
      }
    }

    getNetworkSyncData(): SoundManagerSyncData {
      const freeMusicsNetworkSyncData: SoundSyncData[] = [];