Skip to content

Commit

Permalink
#92: Log an error in case of an unsupported cross-origin HTTP request
Browse files Browse the repository at this point in the history
  • Loading branch information
kynikos committed May 31, 2012
1 parent d3b4bc4 commit c4c9224
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
26 changes: 23 additions & 3 deletions src/modules/MW.js
Expand Up @@ -113,7 +113,7 @@ WM.MW = new function () {
if (!api) {
api = wikiPaths.local.api;
}
GM_xmlhttpRequest({
var query = {
method: "GET",
url: api + "?format=json" + joinParams(params),
onload: function (res) {
Expand All @@ -133,7 +133,18 @@ WM.MW = new function () {
onerror: function (res) {
WM.Log.logError("Failed query: " + res.finalUrl);
}
});
};

try {
GM_xmlhttpRequest(query);
}
catch (err) {
WM.Log.logError("Failed HTTP request - " + err +
"\nIf the error above is \"Security violation\" " +
"you are probably using Wiki Monkey without " +
"Scriptish, Greasemonkey or Tampermonkey: " +
"see https://github.com/kynikos/wiki-monkey/wiki");
}
};

this.callAPIPost = function (params, api, call, callArgs) {
Expand Down Expand Up @@ -190,7 +201,16 @@ WM.MW = new function () {
query.headers = {"Content-type": "application/x-www-form-urlencoded"};
}

GM_xmlhttpRequest(query);
try {
GM_xmlhttpRequest(query);
}
catch (err) {
WM.Log.logError("Failed HTTP request - " + err +
"\nIf the error above is \"Security violation\" " +
"you are probably using Wiki Monkey without " +
"Scriptish, Greasemonkey or Tampermonkey: " +
"see https://github.com/kynikos/wiki-monkey/wiki");
}
};

var joinParams = function (params) {
Expand Down
16 changes: 13 additions & 3 deletions src/plugins/ArchWikiTemplateAUR.js
Expand Up @@ -21,7 +21,7 @@ WM.Plugins.ArchWikiTemplateAUR = new function () {
this.doReplaceContinue = function (source, newText, links, index, call, callArgs) {
if (links[index]) {
WM.Log.logInfo("Processing " + links[index][0] + "...");
GM_xmlhttpRequest({
var query = {
method: "GET",
url: links[index][1],
onload: function (res) {
Expand All @@ -44,8 +44,18 @@ WM.Plugins.ArchWikiTemplateAUR = new function () {
},
onerror: function (res) {
WM.Log.logError("Failed query: " + res.finalUrl);
}
});
},
};
try {
GM_xmlhttpRequest(query);
}
catch (err) {
WM.Log.logError("Failed HTTP request - " + err +
"\nIf the error above is \"Security violation\" " +
"you are probably using Wiki Monkey without " +
"Scriptish, Greasemonkey or Tampermonkey: " +
"see https://github.com/kynikos/wiki-monkey/wiki");
}
}
else {
call(source, newText, callArgs);
Expand Down

0 comments on commit c4c9224

Please sign in to comment.