Chat completion 401 when no Authorization header
When we send a request to `/api/chat/completions` without the `Authorization` header, the server just crashes and creates a stack trace, returning "Internal Server Error" to the calling client. With this fix, the server sends a 401 to the client with the content `{"detail": "Not authenticated"}`.
			
			
This commit is contained in:
		
							parent
							
								
									1d225dd804
								
							
						
					
					
						commit
						eab30781e0
					
				|  | @ -761,10 +761,22 @@ class PipelineMiddleware(BaseHTTPMiddleware): | ||||||
|         # Parse string to JSON |         # Parse string to JSON | ||||||
|         data = json.loads(body_str) if body_str else {} |         data = json.loads(body_str) if body_str else {} | ||||||
| 
 | 
 | ||||||
|         user = get_current_user( |         try: | ||||||
|             request, |             user = get_current_user( | ||||||
|             get_http_authorization_cred(request.headers["Authorization"]), |                 request, | ||||||
|         ) |                 get_http_authorization_cred(request.headers["Authorization"]), | ||||||
|  |             ) | ||||||
|  |         except KeyError as e: | ||||||
|  |             if len(e.args) > 1: | ||||||
|  |                 return JSONResponse( | ||||||
|  |                     status_code=e.args[0], | ||||||
|  |                     content={"detail": e.args[1]}, | ||||||
|  |                 ) | ||||||
|  |             else: | ||||||
|  |                 return JSONResponse( | ||||||
|  |                     status_code=status.HTTP_401_UNAUTHORIZED, | ||||||
|  |                     content={"detail": "Not authenticated"}, | ||||||
|  |                 ) | ||||||
| 
 | 
 | ||||||
|         try: |         try: | ||||||
|             data = filter_pipeline(data, user) |             data = filter_pipeline(data, user) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue