forked from open-webui/open-webui
		
	feat: better error handling for ollama reverse proxy
This commit is contained in:
		
							parent
							
								
									346b0df811
								
							
						
					
					
						commit
						25987fe3c9
					
				
					 1 changed files with 22 additions and 17 deletions
				
			
		|  | @ -59,6 +59,7 @@ def proxy(path): | ||||||
|     else: |     else: | ||||||
|         pass |         pass | ||||||
| 
 | 
 | ||||||
|  |     try: | ||||||
|         # Make a request to the target server |         # Make a request to the target server | ||||||
|         target_response = requests.request( |         target_response = requests.request( | ||||||
|             method=request.method, |             method=request.method, | ||||||
|  | @ -68,6 +69,8 @@ def proxy(path): | ||||||
|             stream=True,  # Enable streaming for server-sent events |             stream=True,  # Enable streaming for server-sent events | ||||||
|         ) |         ) | ||||||
| 
 | 
 | ||||||
|  |         target_response.raise_for_status() | ||||||
|  | 
 | ||||||
|         # Proxy the target server's response to the client |         # Proxy the target server's response to the client | ||||||
|         def generate(): |         def generate(): | ||||||
|             for chunk in target_response.iter_content(chunk_size=8192): |             for chunk in target_response.iter_content(chunk_size=8192): | ||||||
|  | @ -80,6 +83,8 @@ def proxy(path): | ||||||
|             response.headers[key] = value |             response.headers[key] = value | ||||||
| 
 | 
 | ||||||
|         return response |         return response | ||||||
|  |     except Exception as e: | ||||||
|  |         return jsonify({"detail": "Server Connection Error", "message": str(e)}), 400 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| if __name__ == "__main__": | if __name__ == "__main__": | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timothy J. Baek
						Timothy J. Baek