diff --git a/bin/slubsipbuilderbagit.pl b/bin/slubsipbuilderbagit.pl index 29f2ee696ec37805a803748e5e936340e2b5104d..c1412d67b232abd6b661b058f06ca163682d5898 100644 --- a/bin/slubsipbuilderbagit.pl +++ b/bin/slubsipbuilderbagit.pl @@ -132,21 +132,39 @@ package SLUB::LZA::SIPBuilderBagIt; my $ppn = shift; my $marc21; - eval { + my $use_fallback; + + eval { # try SWB $marc21 = SLUB::LZA::SIPBuilderBagIt::get_marc21_from($swb_url, $ppn, $searchkey_swb, $recordschema_swb); }; - if ($@) { - # Fallback to K10plus PPN + if ($@) { # error + say "$@" unless (! $with_debug); if ($@ =~ m#ERROR: Did not get any <recordData/> for PPN#) { print_scalar_data("", "WARNING: '$ppn' not a SWB PPN, fallback to K10plus", "", "yellow"); - $marc21 = SLUB::LZA::SIPBuilderBagIt::get_marc21_from($swb_url, $ppn, $searchkey_k10p, $recordschema_k10p); + $use_fallback = 1; } else { die "$@"; # throw exception again } } - print_scalar_data("", "INFO: Found metadata for PPN '$ppn'", "", "white"); + if ($use_fallback) { + eval { # try K10plus + $marc21 = SLUB::LZA::SIPBuilderBagIt::get_marc21_from($swb_url, $ppn, $searchkey_k10p, $recordschema_k10p); + }; + if ($@) { # error + say "$@" unless (!$with_debug); + if ($@ =~ m#ERROR: Did not get any <recordData/> for PPN#) { + print_scalar_data("", "ERROR: '$ppn' also not a K10plus PPN", "", "red"); + exit 1; + } + else { + die "$@"; # throw exception again + } + } + } + + print_scalar_data("", "INFO: Found metadata for PPN '$ppn'", "", "white"); return $marc21; }