 +            $sync->update( { 'lastsync' => substr($cause, $i + 14, 19) } );
 +        } elsif ($cause =~ /Oppdaterte felt/) {
 +            # The request was succesfull, even if not reported with status=1
-+            $sync->update( { 'syncstatus' => 'synced' } );
-+            $sync->update( { 'lastsync' => $response->{'server_tid'} } );
++            $sync->update( { 'syncstatus' => 'synced', 'lastsync' => $response->{'server_tid'} } );
 +        } elsif ($cause =~ /Person med gitt fnr finnes allerede i registeret med nummer/) {
 +            # Patron was registered as new, withouth checking for existing patron in NL using the given fnr
 +            # We attemt to sync the new cardnumber to NL.

+            # Because of staff mistakes, patrons are sometimes registered with existing cardnumber
+            # without checking if they allready exist in NL.
+            # We set syncstatus to 'edited', so that it might be correctly synced next time.
+            # The lastsync value is arbritary, and will be corrected if NL complains
+            $sync->update( { 'syncstatus' => 'edited', 'lastsync' => `date +"%Y-%m-%dT%T"` } );
+        } elsif ($cause =~ /lnr finnes ikke i registeret/) {
+            # Make sure syncstatus is 'new'
+            $sync->update( { 'syncstatus' => 'new' } );

+
+            $cause = $response->result->{'melding'};
+            if ( $response->{'status'} && $response->{'status'} == 1 || ($cause && $cause =~ /Oppdaterte felt/)) {
+                $sync->update( { 'syncstatus' => 'synced', 'lastsync' => $response->{'server_tid'} } );
+            }
+        }
+
     }
     return $response;

@@ -564,6 +610,23 @@ sub _format_soap_error {

 }

