diff --git a/src/core/friendly_errors/file_errors.js b/src/core/friendly_errors/file_errors.js index 4bc3bd85cb..565085ad49 100644 --- a/src/core/friendly_errors/file_errors.js +++ b/src/core/friendly_errors/file_errors.js @@ -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' + }; } }; /** diff --git a/src/io/files.js b/src/io/files.js index 49ae034753..eea5dffdb9 100644 --- a/src/io/files.js +++ b/src/io/files.js @@ -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; + } + } + ); }; /** diff --git a/translations/en/translation.json b/translations/en/translation.json index f0afe49617..6fa87add31 100644 --- a/translations/en/translation.json +++ b/translations/en/translation.json @@ -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}}", diff --git a/translations/es/translation.json b/translations/es/translation.json index 7ab126b1d9..8106f119e3 100644 --- a/translations/es/translation.json +++ b/translations/es/translation.json @@ -5,6 +5,7 @@ "fileLoadError": { "bytes": "", "font": "", + "get": "", "gif": "", "image": "", "json": "",