pierrejeambrun commented on code in PR #58016:
URL: https://github.com/apache/airflow/pull/58016#discussion_r2572204454
##########
airflow-core/src/airflow/ui/src/queries/useTrigger.ts:
##########
@@ -62,7 +63,22 @@ export const useTrigger = ({ dagId, onSuccessConfirm }: {
dagId: string; onSucce
}
};
- const onError = (_error: unknown) => {
+ const onError = (_error: Error) => {
+ // Check if error is a 403 (Forbidden) status
+ if (isHttpError(_error, 403)) {
+ toaster.create({
+ description: _error.message,
+ title: translate("triggerDag.toaster.error.forbidden.title", "Trigger
DAG Permission Denied"),
+ type: "error",
+ });
+ } else {
Review Comment:
You don't need this first case.
Just show the second case always that can handle any type of backend error,
and display the error.
##########
airflow-core/src/airflow/ui/src/utils/httpErrors.ts:
##########
@@ -0,0 +1,54 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Checks if an error object has a specific HTTP status code
+ * Handles various error formats including direct status and response.status
+ *
+ * @param error - The error object to check
+ * @param status - The HTTP status code to match
+ * @returns true if the error has the specified status code, false otherwise
+ */
+export const isHttpError = (error: unknown, status: number): boolean => {
+ if (error === null || error === undefined || typeof error !== "object") {
+ return false;
+ }
+
+ // Check for direct status property
+ if ("status" in error && (error as { status?: unknown }).status === status) {
+ return true;
+ }
+
+ // Check for response.status (common in fetch errors)
+ if ("response" in error) {
Review Comment:
You will be able to remove this entire file.
--
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]