Browse Source

ObjectLoader.loadAsync: wrap JSON.parse in try/catch for consistent error handling (#32947)

AI-Glow 2 weeks ago
parent
commit
65f616d29e
1 changed files with 11 additions and 1 deletions
  1. 11 1
      src/loaders/ObjectLoader.js

+ 11 - 1
src/loaders/ObjectLoader.js

@@ -170,7 +170,17 @@ class ObjectLoader extends Loader {
 
 		const text = await loader.loadAsync( url, onProgress );
 
-		const json = JSON.parse( text );
+		let json;
+
+		try {
+
+			json = JSON.parse( text );
+
+		} catch ( e ) {
+
+			throw new Error( 'ObjectLoader: Can\'t parse ' + url + '. ' + e.message );
+
+		}
 
 		const metadata = json.metadata;
 

粤ICP备19079148号