From 0739be1763426315ba47f9f0cd6589e40094a271 Mon Sep 17 00:00:00 2001 From: nishiki Date: Sun, 27 Apr 2014 15:17:37 +0200 Subject: [PATCH] fix bug when the MPW server haven't data --- MPW/MPW.rb | 2 ++ MPW/Sync/MPWSync.rb | 13 +++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/MPW/MPW.rb b/MPW/MPW.rb index 05da9cf..71e6f3d 100644 --- a/MPW/MPW.rb +++ b/MPW/MPW.rb @@ -273,6 +273,8 @@ module MPW def sync(data_remote, last_update) if !data_remote.instance_of?(Array) return false + else data_remote.nil? || data_remote.empty? + return true end @data.each do |l| diff --git a/MPW/Sync/MPWSync.rb b/MPW/Sync/MPWSync.rb index da62975..8e6c700 100644 --- a/MPW/Sync/MPWSync.rb +++ b/MPW/Sync/MPWSync.rb @@ -67,9 +67,14 @@ module MPW end if !defined?(msg['error']) - error_msg = I18n.t('error.sync.communication') + @error_msg = I18n.t('error.sync.communication') return nil - elsif msg['error'].nil? + elsif !msg['error'].nil? + @error_msg = I18n.t(msg['error']) + return nil + elsif msg['data'].nil? || msg['data'].empty? + return [] + else tmp_file = tmpfile File.open(tmp_file, 'w') do |file| file << msg['data'] @@ -83,11 +88,7 @@ module MPW File.unlink(tmp_file) return mpw.search - else - @error_msg = I18n.t(msg['error']) - return nil end - end # Update the remote data