Skip to content

Commit 71ddfb8

Browse files
committed
Fix #20 - regression from ealier change
1 parent fe78ac4 commit 71ddfb8

4 files changed

Lines changed: 32 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Changelog
2+
## [20251227.17] - 2025-12-27
3+
### Fixed
4+
Fixed bug introduced by fix in previous release
25

36
## [20251224.16] - 2025-12-24
47
### Added

piwigoPublish.lrplugin/Info.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@ return {
5959

6060
LrPluginInfoProvider = 'PluginInfo.lua',
6161

62-
VERSION = { major=20251224, minor=16, revision=0 },
62+
VERSION = { major=20251227, minor=17, revision=0 },
6363
}

piwigoPublish.lrplugin/Init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,5 @@ end
7272

7373
_G.PiwigoBusy = false
7474
_G.iconPath = _PLUGIN:resourceId("icons/icon_med.png")
75-
_G.pluginVersion = "20251224.16"
75+
_G.pluginVersion = "20251228.17"
7676

piwigoPublish.lrplugin/PiwigoAPI.lua

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,15 @@ function PiwigoAPI.pwConnect(propertyTable)
681681
if (httpHeaders.status == 201) or (httpHeaders.status == 200) then
682682
-- successful connection to Piwigo
683683
-- Now check login result
684-
local rtnBody = JSON:decode(httpResponse)
684+
-- Decode JSON safely
685+
local ok, rtnBody = pcall( JSON.decode, JSON, httpResponse )
686+
if not ok or type(rtnBody) ~= "table" then
687+
LrDialogs.message(
688+
"Cannot log in to Piwigo",
689+
"Invalid or unreadable server response"
690+
)
691+
return false
692+
end
685693
if rtnBody.stat == "ok" then
686694
-- login ok - store session cookies
687695
local cookies = {}
@@ -705,18 +713,28 @@ function PiwigoAPI.pwConnect(propertyTable)
705713
propertyTable.cookieHeader = table.concat(propertyTable.cookies,"; ")
706714
propertyTable.Connected = true
707715
else
708-
LrDialogs.message("Cannot log in to Piwigo - ", rtnBody.err .. ", " .. rtnBody.message)
716+
LrDialogs.message(
717+
"Cannot log in to Piwigo",
718+
tostring(rtnBody.err or "Unknown error")
719+
.. (rtnBody.message and (", " .. rtnBody.message) or "")
720+
)
709721
return false
710722
end
711723
else
712-
if httpHeaders.error then
713-
statusDes = httpHeaders.error.name
714-
status = httpHeaders.error.errorCode
724+
local statusCode, statusDesc
725+
status = httpHeaders and httpHeaders.status
726+
if httpHeaders and httpHeaders.error then
727+
statusCode = httpHeaders.error.errorCode or "?"
728+
statusDesc = httpHeaders.error.name or "Unknown error"
715729
else
716-
statusDes = httpHeaders.statusDes or httpHeaders.statusDesc
717-
status = httpHeaders.status
730+
statusCode = status or "?"
731+
statusDesc = (httpHeaders and (httpHeaders.statusDes or httpHeaders.statusDesc)) or ""
718732
end
719-
LrDialogs.message("Cannot log in to Piwigo - ", status .. ", " .. statusDes)
733+
734+
LrDialogs.message(
735+
"Cannot log in to Piwigo",
736+
tostring(statusCode) .. (statusDesc ~= "" and (", " .. statusDesc) or "")
737+
)
720738
return false
721739
end
722740

@@ -1696,8 +1714,7 @@ function PiwigoAPI.httpPostMultiPart(propertyTable, params)
16961714
end
16971715
if httpHeaders then
16981716
postHeaders.status = httpHeaders.status
1699-
postHeaders.statusDesc = httpHeaders.statusDes or httpHeaders.statusDesc
1700-
1717+
postHeaders.statusDesc = (httpHeaders and (httpHeaders.statusDes or httpHeaders.statusDesc)) or ""
17011718
end
17021719
if not body then
17031720
postResponse.status = false

0 commit comments

Comments
 (0)