| 
				
			 | 
			
			
				@@ -130,29 +130,36 @@ class Person(NamedTuple): 
			 | 
		
	
		
			
			| 
				130
			 | 
			
				130
			 | 
			
			
				             ) 
			 | 
		
	
		
			
			| 
				131
			 | 
			
				131
			 | 
			
			
				             return None 
			 | 
		
	
		
			
			| 
				132
			 | 
			
				132
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				133
			 | 
			
				
			 | 
			
			
				-    def create(self) -> Optional[Person]: 
			 | 
		
	
		
			
			| 
				
			 | 
			
				133
			 | 
			
			
				+    def create(self) -> Union[Person, NetworkError]: 
			 | 
		
	
		
			
			| 
				134
			 | 
			
				134
			 | 
			
			
				         """ Create a new Person from the current attributes. As tuples are 
			 | 
		
	
		
			
			| 
				135
			 | 
			
				135
			 | 
			
			
				         immutable, a new Person with the correct id is returned. """ 
			 | 
		
	
		
			
			| 
				136
			 | 
			
				
			 | 
			
			
				-        req = requests.post( 
			 | 
		
	
		
			
			| 
				137
			 | 
			
				
			 | 
			
			
				-            urljoin(SERVER_URL, "people"), 
			 | 
		
	
		
			
			| 
				138
			 | 
			
				
			 | 
			
			
				-            json={"person": {"name": self.name, "active": True}}, 
			 | 
		
	
		
			
			| 
				139
			 | 
			
				
			 | 
			
			
				-        ) 
			 | 
		
	
		
			
			| 
				140
			 | 
			
				136
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				141
			 | 
			
				137
			 | 
			
			
				         try: 
			 | 
		
	
		
			
			| 
				142
			 | 
			
				
			 | 
			
			
				-            data = req.json() 
			 | 
		
	
		
			
			| 
				143
			 | 
			
				
			 | 
			
			
				-        except ValueError: 
			 | 
		
	
		
			
			| 
				144
			 | 
			
				
			 | 
			
			
				-            LOG.error( 
			 | 
		
	
		
			
			| 
				145
			 | 
			
				
			 | 
			
			
				-                "Did not get JSON on adding Person (%s): %s", 
			 | 
		
	
		
			
			| 
				146
			 | 
			
				
			 | 
			
			
				-                req.status_code, 
			 | 
		
	
		
			
			| 
				147
			 | 
			
				
			 | 
			
			
				-                req.content, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				138
			 | 
			
			
				+            req = requests.post( 
			 | 
		
	
		
			
			| 
				
			 | 
			
				139
			 | 
			
			
				+                urljoin(SERVER_URL, "people"), 
			 | 
		
	
		
			
			| 
				
			 | 
			
				140
			 | 
			
			
				+                json={ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				141
			 | 
			
			
				+                    "person": { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				142
			 | 
			
			
				+                        "full_name": self.full_name, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				143
			 | 
			
			
				+                        "display_name": self.display_name, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				144
			 | 
			
			
				+                        "active": True, 
			 | 
		
	
		
			
			| 
				
			 | 
			
				145
			 | 
			
			
				+                    } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				146
			 | 
			
			
				+                }, 
			 | 
		
	
		
			
			| 
				148
			 | 
			
				147
			 | 
			
			
				             ) 
			 | 
		
	
		
			
			| 
				149
			 | 
			
				
			 | 
			
			
				-            return None 
			 | 
		
	
		
			
			| 
				
			 | 
			
				148
			 | 
			
			
				+            req.raise_for_status() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				149
			 | 
			
			
				+            data = req.json() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				150
			 | 
			
			
				+            return Person.from_dict(data["person"]) 
			 | 
		
	
		
			
			| 
				150
			 | 
			
				151
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				151
			 | 
			
				
			 | 
			
			
				-        if "error" in data or req.status_code != 201: 
			 | 
		
	
		
			
			| 
				152
			 | 
			
				
			 | 
			
			
				-            LOG.error("Could not create Person (%s): %s", req.status_code, data) 
			 | 
		
	
		
			
			| 
				153
			 | 
			
				
			 | 
			
			
				-            return None 
			 | 
		
	
		
			
			| 
				
			 | 
			
				152
			 | 
			
			
				+        except requests.ConnectionError as e: 
			 | 
		
	
		
			
			| 
				
			 | 
			
				153
			 | 
			
			
				+            LOG.exception(e) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				154
			 | 
			
			
				+            return NetworkError.ConnectionFailure 
			 | 
		
	
		
			
			| 
				154
			 | 
			
				155
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				155
			 | 
			
				
			 | 
			
			
				-        return Person.from_dict(data["person"]) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				156
			 | 
			
			
				+        except requests.HTTPError as e: 
			 | 
		
	
		
			
			| 
				
			 | 
			
				157
			 | 
			
			
				+            LOG.exception(e) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				158
			 | 
			
			
				+            return NetworkError.HttpFailure 
			 | 
		
	
		
			
			| 
				
			 | 
			
				159
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				160
			 | 
			
			
				+        except ValueError as e: 
			 | 
		
	
		
			
			| 
				
			 | 
			
				161
			 | 
			
			
				+            LOG.exception(e) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				162
			 | 
			
			
				+            return NetworkError.InvalidData 
			 | 
		
	
		
			
			| 
				156
			 | 
			
				163
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				157
			 | 
			
				164
			 | 
			
			
				     def set_active(self, new_state=True) -> Optional[Person]: 
			 | 
		
	
		
			
			| 
				158
			 | 
			
				165
			 | 
			
			
				         req = requests.patch( 
			 |