From 036ad72a2fec849a7a1b8674b21c17766da3d59c Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Mon, 2 Feb 2015 00:17:14 +0100 Subject: Improve error message for API warnings Display more information if the upload fails because the API returned a warning. Therefor the warnings tag is parsed if the result is Warning, and the keys of the tag are shown as error message (e. g. 'badfilename'). Previously, the error message was only 'Warning', which did not help users to identify the problem. - modify MediaWikiApi.upload to give a more specific error message for API warnings Fix #36 --- mediawiki.lrdevplugin/MediaWikiApi.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'mediawiki.lrdevplugin') diff --git a/mediawiki.lrdevplugin/MediaWikiApi.lua b/mediawiki.lrdevplugin/MediaWikiApi.lua index cc1c322..130fbb5 100755 --- a/mediawiki.lrdevplugin/MediaWikiApi.lua +++ b/mediawiki.lrdevplugin/MediaWikiApi.lua @@ -96,7 +96,7 @@ function MediaWikiApi.performRequest(arguments) elseif resultHeaders.status ~= 200 then LrErrors.throwUserError(LOC('$$$/LrMediaWiki/Api/HttpError=Received HTTP status ^1.', resultHeaders.status)) end - + local resultXml = MediaWikiApi.parseXmlDom(LrXml.parseXml(resultBody)) if resultXml.error then LrErrors.throwUserError(LOC('$$$/LrMediaWiki/Api/MediaWikiError=The MediaWiki error ^1 occured: ^2', resultXml.error.code, resultXml.error.info)) @@ -181,7 +181,7 @@ function MediaWikiApi.upload(fileName, sourceFilePath, text, comment, ignoreWarn if resultHeaders.status ~= 200 then LrErrors.throwUserError(LOC('$$$/LrMediaWiki/Api/HttpError=Received HTTP status ^1.', resultHeaders.status)) end - + local resultXml = MediaWikiApi.parseXmlDom(LrXml.parseXml(resultBody)) if resultXml.error then LrErrors.throwUserError(LOC('$$$/LrMediaWiki/Api/MediaWikiError=The MediaWiki error ^1 occured: ^2', resultXml.error.code, resultXml.error.info)) @@ -190,6 +190,15 @@ function MediaWikiApi.upload(fileName, sourceFilePath, text, comment, ignoreWarn local uploadResult = resultXml.upload.result if uploadResult == 'Success' then return true + elseif uploadResult == 'Warning' then + warnings = '' + for k, v in pairs(resultXml.upload.warnings) do + if warnings ~= '' then + warnings = warnings .. ', ' + end + warnings = warnings .. k + end + return warnings else return uploadResult end -- cgit v1.2.3