Skip to content

Commit

Permalink
added a way to set an error handler in PLCImporter
Browse files Browse the repository at this point in the history
  • Loading branch information
mackuba committed May 16, 2024
1 parent cf205d8 commit 13c911c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/didkit/plc_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class PLCImporter
PLC_SERVICE = 'plc.directory'
MAX_PAGE = 1000

attr_accessor :ignore_errors, :last_date
attr_accessor :ignore_errors, :last_date, :error_handler

def initialize(since: nil)
if since.to_s == 'beginning'
Expand All @@ -22,14 +22,22 @@ def initialize(since: nil)
@last_date = Time.now
@eof = true
end

@ignore_errors = false
end

def plc_service
PLC_SERVICE
end

def ignore_errors=(val)
@ignore_errors = val

if val
@error_handler = proc { |e| "(ignore error)" }
else
@error_handler = nil
end
end

def get_export(args = {})
url = URI("https://#{plc_service}/export")
url.query = URI.encode_www_form(args)
Expand All @@ -48,7 +56,7 @@ def fetch_page
begin
PLCOperation.new(json)
rescue PLCOperation::FormatError, AtHandles::FormatError, ServiceRecord::FormatError => e
ignore_errors ? nil : raise
@error_handler ? @error_handler.call(e) : raise
end
end

Expand Down

0 comments on commit 13c911c

Please sign in to comment.