 +        return ($response, 1);
 +    }
 +
++    if ($cause =~ /slettet tidligere/) {
++        $sync->update( { 'sync' => 0 } );
++        return ($response, 1);
++    }
++
 +    # Something is wrong but we don't know how to handle it, so no point
 +    # in trying again.
 +    return ($response, 1);
  }
 
  =head2 NLGetChanged
-@@ -426,7 +524,7 @@ sub NLUpdateHashedPIN {
+@@ -426,7 +542,7 @@ sub NLUpdateHashedPIN {
      my $borrowersync = Koha::Database->new->schema->resultset('BorrowerSync')->find({
          'synctype'       => 'norwegianpatrondb',
          'borrowernumber' => $borrowernumber,

+        # Make sure syncstatus is 'new'
+        $sync->update( { 'syncstatus' => 'new' } );
+        return ($response, 0);
+    }
+
+    if ($cause =~ /Mangler verdi for sist_endret/) {
+        # Set an arbritary value to missing laststync, it will be corrected on next iteration
+        my $now = `date +"%Y-%m-%dT%T"`;
+        chomp($now);
+        $sync->update( { 'lastsync' => $now } );
+        return ($response, 0);
     }
-    return $response;

+    if ($cause =~ /SIST_ENDRET/) {
+        # NL has different timestamp; returnin an error like this:
+        #  endre: Uoverensstemmelse med gjeldende data i basen:

 )] );
 Exporter::export_ok_tags('all');

@@ -230,6 +231,19 @@ sub NLSync {
         }
     }

+    # NLSync should never have been called, this patron has no row in borrower_sync
+    return unless $sync;
+
+    if (length($sync->hashed_pin) != 32) {
+        # NL password is assumed to be a hashed 4-digit PIN-code. The hash length should
+        # be excactly 32.
+
+        # Turn off any further syncing
+        $sync->update( { 'sync' => 0 } );
+
+        return;
+    }
+
     my $client = SOAP::Lite
         ->on_action( sub { return '""';})
         ->uri( $nl_uri )
@@ -237,33 +251,135 @@ sub NLSync {

     my $cardnumber = SOAP::Data->name( 'lnr' => $patron->cardnumber );

