kaxil commented on code in PR #45043:
URL: https://github.com/apache/airflow/pull/45043#discussion_r1891173474


##########
task_sdk/src/airflow/sdk/api/client.py:
##########
@@ -161,9 +164,19 @@ class ConnectionOperations:
     def __init__(self, client: Client):
         self.client = client
 
-    def get(self, conn_id: str) -> ConnectionResponse:
+    def get(self, conn_id: str) -> ConnectionResponse | ErrorResponse:
         """Get a connection from the API server."""
-        resp = self.client.get(f"connections/{conn_id}")
+        try:
+            resp = self.client.get(f"connections/{conn_id}")
+        except ServerResponseError as e:
+            if e.response.status_code == HTTPStatus.NOT_FOUND:
+                log.error(
+                    "Connection not found",
+                    conn_id=conn_id,
+                    detail=e.detail,
+                    status_code=e.response.status_code,
+                )
+                return ErrorResponse(error=ErrorType.CONNECTION_NOT_FOUND, 
detail={"conn_id": conn_id})

Review Comment:
   Yea, I needed to pass a message from the supervisor to the task runner when 
the API returned 404. Without this, the supervisor will crash.
   
   I had 2 options, either to catch the exception here in the client.py or in 
`_handle_request` in Supervisor. I opted to do it here, since doing it in 
handle request didn't feel right -- just because I thought API client should be 
able to handle the status code and pass the info -- as part of its contract.
   
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to