Skip to content
Open
Show file tree
Hide file tree
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
Expand Up @@ -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'
};
}
};
/**
Expand Down
44 changes: 42 additions & 2 deletions src/io/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
);
};

/**
Expand Down
1 change: 1 addition & 0 deletions translations/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}}",
Expand Down
1 change: 1 addition & 0 deletions translations/es/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"fileLoadError": {
"bytes": "",
"font": "",
"get": "",
"gif": "",
"image": "",
"json": "",
Expand Down