diff options
author | Robin Krahl <me@robin-krahl.de> | 2015-02-02 00:17:14 +0100 |
---|---|---|
committer | Robin Krahl <me@robin-krahl.de> | 2015-02-02 00:17:14 +0100 |
commit | 036ad72a2fec849a7a1b8674b21c17766da3d59c (patch) | |
tree | 2d3f6faa63b2c68d355a6bf6b628d372d1c70640 | |
parent | b6252c99c9b7d60a5bdc85a67d235277307e120f (diff) | |
download | LrMediaWiki-036ad72a2fec849a7a1b8674b21c17766da3d59c.tar.gz LrMediaWiki-036ad72a2fec849a7a1b8674b21c17766da3d59c.tar.bz2 |
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
-rwxr-xr-x | mediawiki.lrdevplugin/MediaWikiApi.lua | 13 |
1 files changed, 11 insertions, 2 deletions
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 |