From d254beb1ab36d71fdb9fa02487ce6376f0942ba7 Mon Sep 17 00:00:00 2001 From: Wouter R Date: Fri, 20 Dec 2013 17:11:58 +0100 Subject: [PATCH] Do not generate error when printer device exists without accompanying server. Fixes https://github.com/Doodle3D/doodle3d-client/issues/139. --- src/rest/api/api_config.lua | 20 +++++++++----------- src/rest/api/api_network.lua | 6 ++---- src/rest/api/api_update.lua | 6 ++---- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/rest/api/api_config.lua b/src/rest/api/api_config.lua index 4c5518f..9f90661 100644 --- a/src/rest/api/api_config.lua +++ b/src/rest/api/api_config.lua @@ -29,10 +29,8 @@ local function operationsAccessOrFail(request, response) end local rv, printerState = printerAPI.state(request, response, true) - if(rv == false) then - response:setError("Could not get printer state") - return false - end + -- NOTE: rv being false means a printer device exists but no server is running for it, so it cannot be 'busy' + if rv == false then return true end if printerState == 'buffering' or printerState == 'printing' or printerState == 'stopping' then response:setFail("Printer is busy, please wait") @@ -97,16 +95,16 @@ function M.all_GET(request, response) end --- Reset specific setting to default value --- When an setting has a subSection only the setting in it's current subSection is reset. --- For example you want to reset setting _printer.startcode_ --- and it has it's _subSection_ set to 'printer_type' --- and printer.type is set to 'ultimaker' then +-- When an setting has a subSection only the setting in it's current subSection is reset. +-- For example you want to reset setting _printer.startcode_ +-- and it has it's _subSection_ set to 'printer_type' +-- and printer.type is set to 'ultimaker' then -- only the printer.startcode under the ultimaker subsection is removed. function M.reset_POST(request, response) --log:info("API:reset"); if not operationsAccessOrFail(request, response) then return end response:setSuccess() - + for k,v in pairs(request:getAll()) do --log:info(" "..k..": "..v); local r,m = settings.reset(k); @@ -115,12 +113,12 @@ function M.reset_POST(request, response) end end ---- Reset all settings to default value +--- Reset all settings to default value function M.resetall_POST(request, response) if not operationsAccessOrFail(request, response) then return end response:setSuccess() settings.resetAll() - + for k,v in pairs(settings.getAll()) do response:addData(k,v) end diff --git a/src/rest/api/api_network.lua b/src/rest/api/api_network.lua index 60158a7..e29d1d5 100644 --- a/src/rest/api/api_network.lua +++ b/src/rest/api/api_network.lua @@ -29,10 +29,8 @@ local function operationsAccessOrFail(request, response) end local rv, printerState = printerAPI.state(request, response, true) - if(rv == false) then - response:setError("Could not get printer state") - return false - end + -- NOTE: rv being false means a printer device exists but no server is running for it, so it cannot be 'busy' + if rv == false then return true end if printerState == 'buffering' or printerState == 'printing' or printerState == 'stopping' then response:setFail("Printer is busy, please wait") diff --git a/src/rest/api/api_update.lua b/src/rest/api/api_update.lua index 60f5b56..e76e6bd 100644 --- a/src/rest/api/api_update.lua +++ b/src/rest/api/api_update.lua @@ -34,10 +34,8 @@ local function operationsAccessOrFail(request, response) end local rv, printerState = printerAPI.state(request, response, true) - if(rv == false) then - response:setError("Could not get printer state") - return false - end + -- NOTE: rv being false means a printer device exists but no server is running for it, so it cannot be 'busy' + if rv == false then return true end if printerState == 'buffering' or printerState == 'printing' or printerState == 'stopping' then response:setFail("Printer is busy, please wait")