private void ApiEditExceptionCaught(AsyncApiEdit sender, Exception ex)
{
if (ex is InterwikiException)
{
SkipPage(ex.Message);
}
else if (ex is SpamlistException)
{
string message = "Text '" + (ex as SpamlistException).URL + "' is blocked by spam blacklist";
if (!BotMode)
{
if (!chkSkipSpamFilter.Checked
&& MessageBox.Show(message + ".\r\nTry and edit again?",
"Spam blacklist", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
Start();
return;
}
}
SkipPage(message);
}
else if (ex is ApiErrorException)
{
switch ((ex as ApiErrorException).ErrorCode)
{
case "editconflict":
// TODO: must be a less crude way
MessageBox.Show(this,
"There has been an edit conflict. AWB will now re-apply its changes on the updated page.\r\nPlease re-review the changes before saving. Any Custom edits will be lost, and have to be re-added manually.",
"Edit conflict");
NudgeTimer.Stop();
Start();
break;
case "writeapidenied":
NoWriteApiRight();
break;
case "customcssprotected":
SkipPage("You're not allowed to edit custom CSS pages");
break;
case "customjsprotected":
SkipPage("You're not allowed to edit custom JavaScript pages");
break;
case "badmd5":
SkipPage(
"API MD5 hash error: The page you are editing may contain an unsupported or invalid Unicode character");
break;
case "assertuserfailed":
HandleLogoff();
break;
case "badtoken":
// likely session timeout forced by mediawiki, so just reprocess page
Tools.WriteDebug("ApiExceptionCaught/badtoken", ex.Message);
StartDelayedRestartTimer();
break;
case "blocked":
MessageBox.Show("API reports this user is blocked from editing.",
"User blocked", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
Stop();
break;
case "readonly":
MessageBox.Show(((ApiErrorException)ex).ApiErrorMessage,
"Wiki read-only", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
Stop();
break;
case "tpt-target-page":
SkipPage("Translation pages cannot currently be edited");
break;
case "titleblacklist-forbidden-edit":
SkipPage("TitleBlacklist prevents this title from being created");
break;
default:
Tools.WriteDebug("ApiExceptionCaught", ex.Message);
StartDelayedRestartTimer();
break;
}
}
else if (ex is ApiBlankException)
{
Tools.WriteDebug("ApiBlankException", ex.Message);
StartDelayedRestartTimer();
}
else if (ex is NewMessagesException)
{
WeHaveNewMessages();
}
else if (ex is LoggedOffException)
{
HandleLogoff();
}
else if (ex is CaptchaException)
{
MessageBox.Show("Captcha required, is the user account autoconfirmed etc?", "Captcha Required");
Stop();
}
else if (ex is InvalidTitleException)
{
SkipPage("Invalid title");
}
else if (ex is RedirectToSpecialPageException)
{
SkipPage("Page is a redirect to a special page");
}
else if (ex is WebException || (ex is IOException && ex.Message.Contains("0x2746")))
{
// some 404 error or similar, or "Unable to write data to the transport connection: Unknown error (0x2746)"
StatusLabelText = ex.Message;
if (Tools.WriteDebugEnabled)
Tools.WriteTextFile(ex.Message, "Log.txt", true);
StartDelayedRestartTimer();
}
else if (ex is SharedRepoException)
{
MessageBox.Show("Cannot move this file to the specified target, as it exists in a shared repo (such as commons).", "Target file exists in shared repo");
}
else if (ex is MediaWikiSaysNoException)
{
MessageBox.Show("MediaWiki prevented you from making that edit. Chances are it's spam or abuse filter related", "MediaWiki says no");
SkipPage("Edit blocked by spam/abuse filter");
}
else
{
Stop();
ErrorHandler.HandleException(ex);
}
}