Skip to content

Fixes Issue #5646 (httpGet() not showing friendly error message) #5647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/core/friendly_errors/file_errors.js
Original file line number Diff line number Diff line change
@@ -74,6 +74,13 @@ if (typeof IS_MINIFIED !== 'undefined') {
message: translator('fes.fileLoadError.gif'),
method: 'loadImage'
};
case 9:
return {
message: translator('fes.fileLoadError.get', {
suggestion
}),
method: 'httpGet'
};
}
};
/**
44 changes: 42 additions & 2 deletions src/io/files.js
Original file line number Diff line number Diff line change
@@ -822,8 +822,48 @@ p5.prototype.httpGet = function() {
p5._validateParameters('httpGet', arguments);

const args = Array.prototype.slice.call(arguments);
args.splice(1, 0, 'GET');
return p5.prototype.httpDo.apply(this, args);
const path = args[0];
let datatype;
let data;
let callback;
let errorCallback;

for (let i = 1; i < args.length; i++) {
const arg = args[i];
if (typeof arg === 'string') {
datatype = arg;
} else if (typeof arg === 'object') {
data = arg;
} else if (typeof arg === 'function') {
if (!callback) {
callback = arg;
} else {
errorCallback = arg;
}
}
}

return this.httpDo(
path,
'GET',
datatype,
data,
resp => {
if (callback) {
callback(resp);
} else {
return resp;
}
},
err => {
p5._friendlyFileLoadError(9, path);
if (errorCallback) {
errorCallback(err);
} else {
throw err;
}
}
);
};

/**
1 change: 1 addition & 0 deletions translations/en/translation.json
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
"fileLoadError": {
"bytes": "It looks like there was a problem loading your file. {{suggestion}}",
"font": "It looks like there was a problem loading your font. {{suggestion}}",
"get": "It looks like there was a problem completing your GET request. {{suggestion}}",
"gif": "There was some trouble loading your GIF. Make sure that your GIF is using 87a or 89a encoding.",
"image": "It looks like there was a problem loading your image. {{suggestion}}",
"json": "It looks like there was a problem loading your JSON file. {{suggestion}}",
1 change: 1 addition & 0 deletions translations/es/translation.json
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
"fileLoadError": {
"bytes": "",
"font": "",
"get": "",
"gif": "",
"image": "",
"json": "",