Skip to content

Commit

Permalink
Add network error message (#1281)
Browse files Browse the repository at this point in the history
Fixes #1205

## What is this PR doing?

It adds an error message for blueprint network errors.

## What problem is it solving?

It will help users identify the root cause of blueprints failing.

## How is the problem addressed?

By returning a custom error message with debug instructions.

## Testing Instructions

- Checkout this branch
- [Open Playground with this
blueprint](http://localhost:5400/website-server/#{%20%22features%22:%20{%20%22networking%22:%20true%20},%20%22steps%22:%20[%20{%20%22step%22:%20%22installPlugin%22,%20%22pluginZipFile%22:%20{%20%22resource%22:%20%22url%22,%20%22url%22:%20%22https://github.com/helgatheviking/simple-user-listing-demo-avatars/releases/download/1.0.0/simple-user-listing-demo-avatars.1.0.0.zip%22%20},%20%22options%22:%20{%20%22activate%22:%20true%20}%20}%20]%20})
- Open the browser console and see the new error 

**Note**: The error is currently displayed multiple times because of
uncaught promises somewhere in the code.

---------

Co-authored-by: Adam Zielinski <adam@adamziel.com>
  • Loading branch information
bgrgicak and adamziel authored Apr 24, 2024
1 parent 8ccacca commit fe814ae
Showing 1 changed file with 45 additions and 8 deletions.
53 changes: 45 additions & 8 deletions packages/playground/blueprints/src/lib/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
github.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 'github.com'.
3. Remove the '/blob/' part of the URL.
The resulting URL should look like this:
'''
https://github.com/username/repository/branch/filename
'''
Error:
${e}`
);
}
return new File([await response.blob()], this.name);
}

/**
Expand Down

0 comments on commit fe814ae

Please sign in to comment.