diff --git a/frontend/src/features/auth/api/useAuthLogin.ts b/frontend/src/features/auth/api/useAuthLogin.ts index e2220807..a6b86b1c 100644 --- a/frontend/src/features/auth/api/useAuthLogin.ts +++ b/frontend/src/features/auth/api/useAuthLogin.ts @@ -1,5 +1,7 @@ import { type MutationConfig } from "@services/clients/react-query.client"; import { useMutation } from "@tanstack/react-query"; +import { type AxiosError } from "axios"; +import { toast } from "react-toastify"; import { dominoApiClient } from "services/clients/domino.client"; interface LoginParams { @@ -20,6 +22,14 @@ export const useAuthLogin = ( return useMutation({ mutationFn: async ({ email, password }) => await postAuthLogin({ email, password }), + onError: (e: AxiosError<{ message: string }>) => { + const message = + (e.response?.data?.message ?? e?.message) || "Something went wrong"; + + toast.error(message, { + toastId: message, + }); + }, ...config, }); }; diff --git a/frontend/src/features/auth/api/useAuthRegister.ts b/frontend/src/features/auth/api/useAuthRegister.ts index b1c151a1..fa689b3d 100644 --- a/frontend/src/features/auth/api/useAuthRegister.ts +++ b/frontend/src/features/auth/api/useAuthRegister.ts @@ -1,5 +1,7 @@ import { type MutationConfig } from "@services/clients/react-query.client"; import { useMutation } from "@tanstack/react-query"; +import { type AxiosError } from "axios"; +import { toast } from "react-toastify"; import { dominoApiClient } from "services/clients/domino.client"; interface RegisterParams { @@ -19,6 +21,14 @@ export const useAuthRegister = ( ) => { return useMutation({ mutationFn: async (params) => await postAuthRegister(params), + onError: (e: AxiosError<{ message: string }>) => { + const message = + (e.response?.data?.message ?? e?.message) || "Something went wrong"; + + toast.error(message, { + toastId: message, + }); + }, ...config, }); }; diff --git a/frontend/src/features/myWorkflows/api/runs/useRunReport.ts b/frontend/src/features/myWorkflows/api/runs/useRunReport.ts index 5bc81bd4..e993de17 100644 --- a/frontend/src/features/myWorkflows/api/runs/useRunReport.ts +++ b/frontend/src/features/myWorkflows/api/runs/useRunReport.ts @@ -1,6 +1,8 @@ import { type QueryConfig } from "@services/clients/react-query.client"; import { skipToken, useQuery } from "@tanstack/react-query"; +import { type AxiosError } from "axios"; import { type taskState } from "features/myWorkflows/types"; +import { toast } from "react-toastify"; import { dominoApiClient } from "services/clients/domino.client"; interface WorkflowRunReportParams { @@ -34,6 +36,18 @@ export const useRunReport = ( ? async () => await getWorkflowRunReport({ runId, workflowId, workspaceId }) : skipToken, + throwOnError(e, _query) { + const message = + ((e as AxiosError<{ detail?: string }>).response?.data?.detail ?? + e?.message) || + "Something went wrong"; + + toast.error(message, { + toastId: message, + }); + + return false; + }, ...config, }); }; diff --git a/frontend/src/features/myWorkflows/api/runs/useRunTaskLogs.ts b/frontend/src/features/myWorkflows/api/runs/useRunTaskLogs.ts index a6459f2c..b04042c4 100644 --- a/frontend/src/features/myWorkflows/api/runs/useRunTaskLogs.ts +++ b/frontend/src/features/myWorkflows/api/runs/useRunTaskLogs.ts @@ -1,5 +1,7 @@ import { type QueryConfig } from "@services/clients/react-query.client"; import { skipToken, useQuery } from "@tanstack/react-query"; +import { type AxiosError } from "axios"; +import { toast } from "react-toastify"; import { dominoApiClient } from "services/clients/domino.client"; interface RunTaskLogsParams { @@ -37,14 +39,37 @@ export const useRunTaskLogs = ( queryFn: !workspaceId || !workflowId || !runId || !taskId || !taskTryNumber ? skipToken - : async () => - await getWorkflowRunTaskLogs({ - workspaceId, - workflowId, - runId, - taskId, - taskTryNumber, - }), + : async () => { + try { + return await getWorkflowRunTaskLogs({ + workspaceId, + workflowId, + runId, + taskId, + taskTryNumber, + }); + } catch (e) { + console.log(e); + throw e; + } + }, + throwOnError(e, _query) { + const message = + ((e as AxiosError<{ detail?: string }>).response?.data?.detail ?? + e?.message) || + "Something went wrong"; + + if (e.response?.status === 404) { + console.log("Logs not found"); + return false; + } + + toast.error(message, { + toastId: message, + }); + + return false; + }, ...config, }); }; diff --git a/frontend/src/features/myWorkflows/api/runs/useRunTaskResult.ts b/frontend/src/features/myWorkflows/api/runs/useRunTaskResult.ts index 7a7bb520..aaf48c44 100644 --- a/frontend/src/features/myWorkflows/api/runs/useRunTaskResult.ts +++ b/frontend/src/features/myWorkflows/api/runs/useRunTaskResult.ts @@ -1,5 +1,7 @@ import { type QueryConfig } from "@services/clients/react-query.client"; import { skipToken, useQuery } from "@tanstack/react-query"; +import { type AxiosError } from "axios"; +import { toast } from "react-toastify"; import { dominoApiClient } from "services/clients/domino.client"; export interface WorkflowRunTaskResultParams { @@ -32,14 +34,32 @@ export const useRunTaskResult = ( queryFn: !runId || !taskId || !taskTryNumber || !workflowId || !workspaceId ? skipToken - : async () => - await getWorkflowRunTaskResult({ + : async () => { + return await getWorkflowRunTaskResult({ runId, taskId, taskTryNumber, workflowId, workspaceId, - }), + }); + }, + throwOnError(e, _query) { + const message = + ((e as AxiosError<{ detail?: string }>).response?.data?.detail ?? + e?.message) || + "Something went wrong"; + + if (e?.response?.status === 404) { + console.log("Results not found"); + return false; + } + + toast.error(message, { + toastId: message, + }); + + return false; + }, ...config, }); }; diff --git a/frontend/src/features/myWorkflows/api/runs/useRunTasks.ts b/frontend/src/features/myWorkflows/api/runs/useRunTasks.ts index d35dfb97..98d49d86 100644 --- a/frontend/src/features/myWorkflows/api/runs/useRunTasks.ts +++ b/frontend/src/features/myWorkflows/api/runs/useRunTasks.ts @@ -1,6 +1,8 @@ import { type IWorkflowRunTasks } from "@features/myWorkflows/types"; import { type InfiniteQueryConfig } from "@services/clients/react-query.client"; import { useInfiniteQuery } from "@tanstack/react-query"; +import { type AxiosError } from "axios"; +import { toast } from "react-toastify"; import { dominoApiClient } from "services/clients/domino.client"; interface WorkflowRunTasksParams { @@ -39,6 +41,18 @@ export const useRunTasks = ( enabled: !!(workspaceId && workflowId && runId), getNextPageParam: (res, _, page) => (res.metadata?.last_page ?? 0) > page ? page + 1 : null, + throwOnError(e, _query) { + const message = + ((e as AxiosError<{ detail?: string }>).response?.data?.detail ?? + e?.message) || + "Something went wrong"; + + toast.error(message, { + toastId: message, + }); + + return false; + }, ...config, }); }; diff --git a/frontend/src/features/myWorkflows/api/runs/useRuns.ts b/frontend/src/features/myWorkflows/api/runs/useRuns.ts index c4286299..536aab40 100644 --- a/frontend/src/features/myWorkflows/api/runs/useRuns.ts +++ b/frontend/src/features/myWorkflows/api/runs/useRuns.ts @@ -1,6 +1,8 @@ import { type IWorkflowRuns } from "@features/myWorkflows/types"; import { type QueryConfig } from "@services/clients/react-query.client"; import { skipToken, useQuery } from "@tanstack/react-query"; +import { type AxiosError } from "axios"; +import { toast } from "react-toastify"; import { dominoApiClient } from "services/clients/domino.client"; interface WorkflowRunParams { @@ -26,6 +28,18 @@ export const useRuns = ( ? skipToken : async () => await getWorkflowRuns({ workspaceId, workflowId, page, pageSize }), + throwOnError(e, _query) { + const message = + ((e as AxiosError<{ detail?: string }>).response?.data?.detail ?? + e?.message) || + "Something went wrong"; + + toast.error(message, { + toastId: message, + }); + + return false; + }, ...config, }); }; diff --git a/frontend/src/features/myWorkflows/api/runs/useStartRun.ts b/frontend/src/features/myWorkflows/api/runs/useStartRun.ts index 56511683..c084f53b 100644 --- a/frontend/src/features/myWorkflows/api/runs/useStartRun.ts +++ b/frontend/src/features/myWorkflows/api/runs/useStartRun.ts @@ -1,6 +1,8 @@ import { type MutationConfig } from "@services/clients/react-query.client"; import { useMutation } from "@tanstack/react-query"; +import { type AxiosError } from "axios"; import { type IPostWorkflowRunIdResponseInterface } from "features/myWorkflows/types/workflow"; +import { toast } from "react-toastify"; import { dominoApiClient } from "services/clients/domino.client"; interface StartRunParams { @@ -23,6 +25,14 @@ export const useStartRun = ( if (!workflowId) throw new Error("no workspace selected"); return await postWorkflowRunId({ workflowId, workspaceId }); }, + onError: (e: AxiosError<{ detail: string }>) => { + const message = + (e.response?.data?.detail ?? e?.message) || "Something went wrong"; + + toast.error(message, { + toastId: message, + }); + }, ...config, }); }; diff --git a/frontend/src/features/myWorkflows/api/workflow/useDeleteWorkflow.ts b/frontend/src/features/myWorkflows/api/workflow/useDeleteWorkflow.ts index e2996ac8..6768df9d 100644 --- a/frontend/src/features/myWorkflows/api/workflow/useDeleteWorkflow.ts +++ b/frontend/src/features/myWorkflows/api/workflow/useDeleteWorkflow.ts @@ -1,6 +1,8 @@ import { type MutationConfig } from "@services/clients/react-query.client"; import { useMutation, useQueryClient } from "@tanstack/react-query"; +import { type AxiosError } from "axios"; import { type IDeleteWorkflowIdResponseInterface } from "features/myWorkflows/types/workflow"; +import { toast } from "react-toastify"; import { dominoApiClient } from "services/clients/domino.client"; interface DeleteWorkflowParams { @@ -30,6 +32,14 @@ export const useDeleteWorkflow = ( queryKey: ["WORKFLOW", workspaceId, workflowId], }); }, + onError: (e: AxiosError<{ detail: string }>) => { + const message = + (e.response?.data?.detail ?? e?.message) || "Something went wrong"; + + toast.error(message, { + toastId: message, + }); + }, ...config, }); }; diff --git a/frontend/src/features/myWorkflows/api/workflow/useWorkflow.ts b/frontend/src/features/myWorkflows/api/workflow/useWorkflow.ts index 5924dd8c..fc606f20 100644 --- a/frontend/src/features/myWorkflows/api/workflow/useWorkflow.ts +++ b/frontend/src/features/myWorkflows/api/workflow/useWorkflow.ts @@ -1,6 +1,8 @@ import { type QueryConfig } from "@services/clients/react-query.client"; import { useQuery, skipToken } from "@tanstack/react-query"; +import { type AxiosError } from "axios"; import { type IGetWorkflowIdResponseInterface } from "features/myWorkflows/types/workflow"; +import { toast } from "react-toastify"; import { dominoApiClient } from "services/clients/domino.client"; interface GetWorkflowByIdParams { @@ -18,6 +20,18 @@ export const useWorkflow = ( workspaceId && workflowId ? async () => await getWorkflowById({ workflowId, workspaceId }) : skipToken, + throwOnError(e, _query) { + const message = + ((e as AxiosError<{ detail?: string }>).response?.data?.detail ?? + e?.message) || + "Something went wrong"; + + toast.error(message, { + toastId: message, + }); + + return false; + }, ...config, }); }; diff --git a/frontend/src/features/myWorkflows/api/workflow/useWorkflows.ts b/frontend/src/features/myWorkflows/api/workflow/useWorkflows.ts index 71d327c3..045b4531 100644 --- a/frontend/src/features/myWorkflows/api/workflow/useWorkflows.ts +++ b/frontend/src/features/myWorkflows/api/workflow/useWorkflows.ts @@ -1,6 +1,8 @@ import { type QueryConfig } from "@services/clients/react-query.client"; import { useQuery, skipToken } from "@tanstack/react-query"; +import { type AxiosError } from "axios"; import { type IGetWorkflowResponseInterface } from "features/myWorkflows/types/workflow"; +import { toast } from "react-toastify"; import { dominoApiClient } from "services/clients/domino.client"; interface GetWorkflowsParams { @@ -18,6 +20,18 @@ export const useWorkflows = ( queryFn: workspaceId ? async () => await getWorkflows({ workspaceId, page, pageSize }) : skipToken, + throwOnError(e, _query) { + const message = + ((e as AxiosError<{ detail?: string }>).response?.data?.detail ?? + e?.message) || + "Something went wrong"; + + toast.error(message, { + toastId: message, + }); + + return false; + }, ...config, }); }; diff --git a/frontend/src/features/workflowEditor/api/workflow/useCreateWorkflow.ts b/frontend/src/features/workflowEditor/api/workflow/useCreateWorkflow.ts index 42d3da44..e7b5744d 100644 --- a/frontend/src/features/workflowEditor/api/workflow/useCreateWorkflow.ts +++ b/frontend/src/features/workflowEditor/api/workflow/useCreateWorkflow.ts @@ -1,7 +1,9 @@ import { type MutationConfig } from "@services/clients/react-query.client"; import { useMutation, useQueryClient } from "@tanstack/react-query"; +import { type AxiosError } from "axios"; import { type IPostWorkflowResponseInterface } from "features/myWorkflows/types"; import { type CreateWorkflowRequest } from "features/workflowEditor/context/types"; +import { toast } from "react-toastify"; import { dominoApiClient } from "services/clients/domino.client"; interface UsePostWorkflow { @@ -27,6 +29,14 @@ export const useCreateWorkflow = ( queryKey: ["WORKFLOWS", workspaceId], }); }, + onError: (e: AxiosError<{ detail: string }>) => { + const message = + (e.response?.data?.detail ?? e?.message) || "Something went wrong"; + + toast.error(message, { + toastId: message, + }); + }, ...config, }); }; diff --git a/frontend/src/features/workflowEditor/api/workflowsExample/getWorkflowExamples.ts b/frontend/src/features/workflowEditor/api/workflowsExample/getWorkflowExamples.ts index 018e5118..f64d1236 100644 --- a/frontend/src/features/workflowEditor/api/workflowsExample/getWorkflowExamples.ts +++ b/frontend/src/features/workflowEditor/api/workflowsExample/getWorkflowExamples.ts @@ -1,7 +1,8 @@ import { type QueryConfig } from "@services/clients/react-query.client"; import { useQuery, skipToken } from "@tanstack/react-query"; -import axios from "axios"; +import axios, { type AxiosError } from "axios"; import { type WorkflowPieceData } from "features/workflowEditor/context/types"; +import { toast } from "react-toastify"; import { type Edge, type Node } from "reactflow"; interface JSONFile { @@ -25,6 +26,18 @@ export const useWorkflowsExamples = ( return useQuery({ queryKey: ["WORKFLOWS-EXAMPLES"], queryFn: fetch ? async () => await getWorkflowsExample() : skipToken, + throwOnError(e, _query) { + const message = + ((e as AxiosError<{ detail?: string }>).response?.data?.detail ?? + e?.message) || + "Something went wrong"; + + toast.error(message, { + toastId: message, + }); + + return false; + }, ...config, }); }; diff --git a/frontend/src/features/workspaces/api/piece/usePieces.ts b/frontend/src/features/workspaces/api/piece/usePieces.ts index f34536e3..b6f55d3e 100644 --- a/frontend/src/features/workspaces/api/piece/usePieces.ts +++ b/frontend/src/features/workspaces/api/piece/usePieces.ts @@ -1,5 +1,7 @@ import { type QueryConfig } from "@services/clients/react-query.client"; import { useQueries } from "@tanstack/react-query"; +import { type AxiosError } from "axios"; +import { toast } from "react-toastify"; import { dominoApiClient } from "services/clients/domino.client"; interface GetRepoPiecesParams { @@ -24,6 +26,16 @@ export const usePieces = ( pending: results.some((result) => result.isPending), }; }, + throwOnError(e: AxiosError<{ detail?: string }>) { + const message = + (e.response?.data?.detail ?? e?.message) || "Something went wrong"; + + toast.error(message, { + toastId: message, + }); + + return false; + }, ...config, }); }; diff --git a/frontend/src/features/workspaces/api/repository/useAddRepository.ts b/frontend/src/features/workspaces/api/repository/useAddRepository.ts index 2adc633d..57a8e7b9 100644 --- a/frontend/src/features/workspaces/api/repository/useAddRepository.ts +++ b/frontend/src/features/workspaces/api/repository/useAddRepository.ts @@ -1,6 +1,8 @@ import { type repositorySource } from "@context/workspaces/types"; import { type MutationConfig } from "@services/clients/react-query.client"; import { useMutation } from "@tanstack/react-query"; +import { type AxiosError } from "axios"; +import { toast } from "react-toastify"; import { dominoApiClient } from "services/clients/domino.client"; export interface AddRepositoryParams { @@ -39,6 +41,14 @@ export const useAddRepository = ( ...params, }); }, + onError: (e: AxiosError<{ detail: string }>) => { + const message = + (e.response?.data?.detail ?? e?.message) || "Something went wrong"; + + toast.error(message, { + toastId: message, + }); + }, ...config, }); }; diff --git a/frontend/src/features/workspaces/api/repository/useDeleteRepository.ts b/frontend/src/features/workspaces/api/repository/useDeleteRepository.ts index aea00b2c..35ffcea3 100644 --- a/frontend/src/features/workspaces/api/repository/useDeleteRepository.ts +++ b/frontend/src/features/workspaces/api/repository/useDeleteRepository.ts @@ -1,5 +1,7 @@ import { type MutationConfig } from "@services/clients/react-query.client"; import { useMutation } from "@tanstack/react-query"; +import { type AxiosError } from "axios"; +import { toast } from "react-toastify"; import { dominoApiClient } from "services/clients/domino.client"; export const useDeleteRepository = ( @@ -9,7 +11,14 @@ export const useDeleteRepository = ( mutationFn: async ({ id }) => { await deleteRepository(id); }, + onError: (e: AxiosError<{ detail: string }>) => { + const message = + (e.response?.data?.detail ?? e?.message) || "Something went wrong"; + toast.error(message, { + toastId: message, + }); + }, ...config, }); }; diff --git a/frontend/src/features/workspaces/api/repository/useRepositories.ts b/frontend/src/features/workspaces/api/repository/useRepositories.ts index 00feced0..7ed99418 100644 --- a/frontend/src/features/workspaces/api/repository/useRepositories.ts +++ b/frontend/src/features/workspaces/api/repository/useRepositories.ts @@ -1,5 +1,7 @@ import { type QueryConfig } from "@services/clients/react-query.client"; import { skipToken, useQuery } from "@tanstack/react-query"; +import { type AxiosError } from "axios"; +import { toast } from "react-toastify"; import { dominoApiClient } from "services/clients/domino.client"; interface PiecesRepositoriesParams { @@ -28,6 +30,18 @@ export const useRepositories = ( queryFn: workspaceId ? async () => await getPiecesRepositories(filters, workspaceId) : skipToken, + throwOnError(e, _query) { + const message = + ((e as AxiosError<{ detail?: string }>).response?.data?.detail ?? + e?.message) || + "Something went wrong"; + + toast.error(message, { + toastId: message, + }); + + return false; + }, ...config, }); }; diff --git a/frontend/src/features/workspaces/api/repository/useRepositoriesReleases.ts b/frontend/src/features/workspaces/api/repository/useRepositoriesReleases.ts index ac398a3f..69ffe951 100644 --- a/frontend/src/features/workspaces/api/repository/useRepositoriesReleases.ts +++ b/frontend/src/features/workspaces/api/repository/useRepositoriesReleases.ts @@ -1,6 +1,8 @@ import { type repositorySource } from "@context/workspaces/types"; import { type MutationConfig } from "@services/clients/react-query.client"; import { useMutation } from "@tanstack/react-query"; +import { type AxiosError } from "axios"; +import { toast } from "react-toastify"; import { dominoApiClient } from "services/clients/domino.client"; export interface RepositoriesReleasesParams { @@ -36,6 +38,14 @@ export const useRepositoriesReleases = ( workspaceId, }); }, + onError: (e: AxiosError<{ detail: string }>) => { + const message = + (e.response?.data?.detail ?? e?.message) || "Something went wrong"; + + toast.error(message, { + toastId: message, + }); + }, ...config, }); }; diff --git a/frontend/src/features/workspaces/api/repository/useRepositorySecrets.ts b/frontend/src/features/workspaces/api/repository/useRepositorySecrets.ts index 906c2d13..8737d1a1 100644 --- a/frontend/src/features/workspaces/api/repository/useRepositorySecrets.ts +++ b/frontend/src/features/workspaces/api/repository/useRepositorySecrets.ts @@ -1,5 +1,7 @@ import { type QueryConfig } from "@services/clients/react-query.client"; import { skipToken, useQuery } from "@tanstack/react-query"; +import { type AxiosError } from "axios"; +import { toast } from "react-toastify"; import { dominoApiClient } from "services/clients/domino.client"; interface RepositorySecretsParams { @@ -21,6 +23,18 @@ export const useRepositorySecrets = ( queryFn: repositoryId ? async () => await getRepositorySecrets(repositoryId) : skipToken, + throwOnError(e, _query) { + const message = + ((e as AxiosError<{ detail?: string }>).response?.data?.detail ?? + e?.message) || + "Something went wrong"; + + toast.error(message, { + toastId: message, + }); + + return false; + }, ...config, }); }; diff --git a/frontend/src/features/workspaces/api/repository/useUpdateRepositorySecret.ts b/frontend/src/features/workspaces/api/repository/useUpdateRepositorySecret.ts index e726460e..d87b149d 100644 --- a/frontend/src/features/workspaces/api/repository/useUpdateRepositorySecret.ts +++ b/frontend/src/features/workspaces/api/repository/useUpdateRepositorySecret.ts @@ -1,6 +1,8 @@ // TODO move to /runs import { type MutationConfig } from "@services/clients/react-query.client"; import { useMutation, useQueryClient } from "@tanstack/react-query"; +import { type AxiosError } from "axios"; +import { toast } from "react-toastify"; import { dominoApiClient } from "services/clients/domino.client"; interface PatchRepositorySecretParams { @@ -25,6 +27,14 @@ export const useUpdateRepositorySecret = ( queryKey: ["REPOSITORIES-SECRETS", repositoryId], }); }, + onError: (e: AxiosError<{ detail: string }>) => { + const message = + (e.response?.data?.detail ?? e?.message) || "Something went wrong"; + + toast.error(message, { + toastId: message, + }); + }, ...config, }); }; diff --git a/frontend/src/features/workspaces/api/workspace/useAcceptWorkspaceInvite.ts b/frontend/src/features/workspaces/api/workspace/useAcceptWorkspaceInvite.ts index 30504b75..6466f209 100644 --- a/frontend/src/features/workspaces/api/workspace/useAcceptWorkspaceInvite.ts +++ b/frontend/src/features/workspaces/api/workspace/useAcceptWorkspaceInvite.ts @@ -1,5 +1,7 @@ import { type MutationConfig } from "@services/clients/react-query.client"; import { useMutation } from "@tanstack/react-query"; +import { type AxiosError } from "axios"; +import { toast } from "react-toastify"; import { dominoApiClient } from "services/clients/domino.client"; interface AcceptWorkspaceInviteParams { @@ -13,6 +15,14 @@ export const useAcceptWorkspaceInvite = ( mutationFn: async (params) => { await acceptWorkspaceInvite(params); }, + onError: (e: AxiosError<{ detail: string }>) => { + const message = + (e.response?.data?.detail ?? e?.message) || "Something went wrong"; + + toast.error(message, { + toastId: message, + }); + }, ...config, }); }; diff --git a/frontend/src/features/workspaces/api/workspace/useCreateWorkspace.ts b/frontend/src/features/workspaces/api/workspace/useCreateWorkspace.ts index 911d03ce..0b797883 100644 --- a/frontend/src/features/workspaces/api/workspace/useCreateWorkspace.ts +++ b/frontend/src/features/workspaces/api/workspace/useCreateWorkspace.ts @@ -1,5 +1,7 @@ import { type MutationConfig } from "@services/clients/react-query.client"; import { useMutation } from "@tanstack/react-query"; +import { type AxiosError } from "axios"; +import { toast } from "react-toastify"; import { dominoApiClient } from "services/clients/domino.client"; type CreateWorkspaceResponse = Record; @@ -13,6 +15,14 @@ export const useCreateWorkspace = ( ) => { return useMutation({ mutationFn: async (params) => await postWorkspaces(params), + onError: (e: AxiosError<{ detail: string }>) => { + const message = + (e.response?.data?.detail ?? e?.message) || "Something went wrong"; + + toast.error(message, { + toastId: message, + }); + }, ...config, }); }; diff --git a/frontend/src/features/workspaces/api/workspace/useDeleteWorkspace.ts b/frontend/src/features/workspaces/api/workspace/useDeleteWorkspace.ts index ffcf5ac4..8a699864 100644 --- a/frontend/src/features/workspaces/api/workspace/useDeleteWorkspace.ts +++ b/frontend/src/features/workspaces/api/workspace/useDeleteWorkspace.ts @@ -1,5 +1,7 @@ import { type MutationConfig } from "@services/clients/react-query.client"; import { useMutation } from "@tanstack/react-query"; +import { type AxiosError } from "axios"; +import { toast } from "react-toastify"; import { dominoApiClient } from "services/clients/domino.client"; export interface DeleteWorkspaceParams { @@ -13,6 +15,14 @@ export const useDeleteWorkspace = ( mutationFn: async ({ workspaceId }) => { await deleteWorkspace({ workspaceId }); }, + onError: (e: AxiosError<{ detail: string }>) => { + const message = + (e.response?.data?.detail ?? e?.message) || "Something went wrong"; + + toast.error(message, { + toastId: message, + }); + }, ...config, }); }; diff --git a/frontend/src/features/workspaces/api/workspace/useGetWorkspaces.ts b/frontend/src/features/workspaces/api/workspace/useGetWorkspaces.ts index 2f595b1c..fc775f13 100644 --- a/frontend/src/features/workspaces/api/workspace/useGetWorkspaces.ts +++ b/frontend/src/features/workspaces/api/workspace/useGetWorkspaces.ts @@ -1,14 +1,32 @@ import { type WorkspaceSummary } from "@context/workspaces/types"; +import { type QueryConfig } from "@services/clients/react-query.client"; import { useQuery } from "@tanstack/react-query"; +import { type AxiosError } from "axios"; +import { toast } from "react-toastify"; import { dominoApiClient } from "services/clients/domino.client"; -const getWorkspaces: () => Promise = async () => { - return await dominoApiClient.get("/workspaces"); -}; - -export const useGetWorkspaces = () => { +export const useGetWorkspaces = ( + config: QueryConfig = {}, +) => { return useQuery({ queryKey: [`WORKSPACES`], queryFn: async () => await getWorkspaces(), + throwOnError(e, _query) { + const message = + ((e as AxiosError<{ detail?: string }>).response?.data?.detail ?? + e?.message) || + "Something went wrong"; + + toast.error(message, { + toastId: message, + }); + + return false; + }, + ...config, }); }; + +const getWorkspaces: () => Promise = async () => { + return await dominoApiClient.get("/workspaces"); +}; diff --git a/frontend/src/features/workspaces/api/workspace/useInviteWorkspace.ts b/frontend/src/features/workspaces/api/workspace/useInviteWorkspace.ts index ce2f73ed..a890cb51 100644 --- a/frontend/src/features/workspaces/api/workspace/useInviteWorkspace.ts +++ b/frontend/src/features/workspaces/api/workspace/useInviteWorkspace.ts @@ -1,5 +1,7 @@ import { type MutationConfig } from "@services/clients/react-query.client"; import { useMutation } from "@tanstack/react-query"; +import { type AxiosError } from "axios"; +import { toast } from "react-toastify"; import { dominoApiClient } from "services/clients/domino.client"; interface InviteWorkspaceParams { @@ -20,6 +22,14 @@ export const useInviteWorkspace = ( if (!workspaceId) throw new Error("No workspace selected"); await inviteWorkspace({ workspaceId, permission, userEmail }); }, + onError: (e: AxiosError<{ detail: string }>) => { + const message = + (e.response?.data?.detail ?? e?.message) || "Something went wrong"; + + toast.error(message, { + toastId: message, + }); + }, ...config, }); }; diff --git a/frontend/src/features/workspaces/api/workspace/useRejectWorkspaceInvite.ts b/frontend/src/features/workspaces/api/workspace/useRejectWorkspaceInvite.ts index fac68718..bb1980cb 100644 --- a/frontend/src/features/workspaces/api/workspace/useRejectWorkspaceInvite.ts +++ b/frontend/src/features/workspaces/api/workspace/useRejectWorkspaceInvite.ts @@ -1,5 +1,7 @@ import { type MutationConfig } from "@services/clients/react-query.client"; import { useMutation } from "@tanstack/react-query"; +import { type AxiosError } from "axios"; +import { toast } from "react-toastify"; import { dominoApiClient } from "services/clients/domino.client"; interface RejectWorkspaceInviteParams { @@ -13,6 +15,14 @@ export const useRejectWorkspaceInvite = ( mutationFn: async (params) => { await rejectWorkspaceInvite(params); }, + onError: (e: AxiosError<{ detail: string }>) => { + const message = + (e.response?.data?.detail ?? e?.message) || "Something went wrong"; + + toast.error(message, { + toastId: message, + }); + }, ...config, }); }; diff --git a/frontend/src/features/workspaces/api/workspace/useRemoveUserFomWorkspace.ts b/frontend/src/features/workspaces/api/workspace/useRemoveUserFomWorkspace.ts index 9f504d79..a2d1f645 100644 --- a/frontend/src/features/workspaces/api/workspace/useRemoveUserFomWorkspace.ts +++ b/frontend/src/features/workspaces/api/workspace/useRemoveUserFomWorkspace.ts @@ -1,5 +1,7 @@ import { type MutationConfig } from "@services/clients/react-query.client"; import { useMutation } from "@tanstack/react-query"; +import { type AxiosError } from "axios"; +import { toast } from "react-toastify"; import { dominoApiClient } from "services/clients/domino.client"; interface RemoveUserWorkspaceParams { @@ -19,6 +21,14 @@ export const useRemoveUserFomWorkspace = ( if (!workspaceId) throw new Error("No workspace selected"); await removeUserFomWorkspace({ userId, workspaceId }); }, + onError: (e: AxiosError<{ detail: string }>) => { + const message = + (e.response?.data?.detail ?? e?.message) || "Something went wrong"; + + toast.error(message, { + toastId: message, + }); + }, ...config, }); }; diff --git a/frontend/src/features/workspaces/api/workspace/useUpdateWorkspace.ts b/frontend/src/features/workspaces/api/workspace/useUpdateWorkspace.ts index 4bcba6b3..272f7d11 100644 --- a/frontend/src/features/workspaces/api/workspace/useUpdateWorkspace.ts +++ b/frontend/src/features/workspaces/api/workspace/useUpdateWorkspace.ts @@ -2,6 +2,8 @@ import { type WorkspaceSummary } from "@context/workspaces/types"; import { type MutationConfig } from "@services/clients/react-query.client"; import { useMutation } from "@tanstack/react-query"; +import { type AxiosError } from "axios"; +import { toast } from "react-toastify"; import { dominoApiClient } from "services/clients/domino.client"; interface PatchWorkspaceParams { @@ -23,6 +25,14 @@ export const useUpdateWorkspace = ( return await patchWorkspace({ workspaceId, ...params }); }, + onError: (e: AxiosError<{ detail: string }>) => { + const message = + (e.response?.data?.detail ?? e?.message) || "Something went wrong"; + + toast.error(message, { + toastId: message, + }); + }, ...config, }); }; diff --git a/frontend/src/features/workspaces/api/workspace/useWorkspaceUsers.ts b/frontend/src/features/workspaces/api/workspace/useWorkspaceUsers.ts index 9ce05c88..71175b3a 100644 --- a/frontend/src/features/workspaces/api/workspace/useWorkspaceUsers.ts +++ b/frontend/src/features/workspaces/api/workspace/useWorkspaceUsers.ts @@ -1,6 +1,8 @@ import { type workspaceStatus } from "@context/workspaces/types"; import { skipToken, useQuery, useQueryClient } from "@tanstack/react-query"; +import { type AxiosError } from "axios"; import { useEffect } from "react"; +import { toast } from "react-toastify"; import { dominoApiClient } from "services/clients/domino.client"; import { type QueryConfig } from "services/clients/react-query.client"; @@ -34,6 +36,18 @@ export const useWorkspaceUsers = ( queryFn: workspaceId ? async () => await getWorkspaceMembers({ page, pageSize, workspaceId }) : skipToken, + throwOnError(e, _query) { + const message = + ((e as AxiosError<{ detail?: string }>).response?.data?.detail ?? + e?.message) || + "Something went wrong"; + + toast.error(message, { + toastId: message, + }); + + return false; + }, ...config, }); diff --git a/frontend/src/services/clients/domino.client.ts b/frontend/src/services/clients/domino.client.ts index c36e3d45..8fa5f1a7 100644 --- a/frontend/src/services/clients/domino.client.ts +++ b/frontend/src/services/clients/domino.client.ts @@ -1,6 +1,5 @@ import axios from "axios"; import { dispatchLogout } from "context/authentication"; -import { toast } from "react-toastify"; import { endpoint } from "../config/endpoints.config"; @@ -25,25 +24,11 @@ dominoApiClient.interceptors.request.use( dominoApiClient.interceptors.response.use( (response) => response.data, async (error) => { - if (error.response.status === 401) { + if (error?.response?.status === 401) { dispatchLogout(); } - const message = - error.response?.data?.detail || - error.response?.data?.message || - error?.message || - "Something went wrong"; - - if (Array.isArray(message)) { - toast.error(message[0].msg, { - toastId: message[0].msg, - }); - } else { - toast.error(message, { - toastId: message, - }); - } + console.log(error); return await Promise.reject(error); }, diff --git a/rest/clients/airflow_client.py b/rest/clients/airflow_client.py index c68e1b83..384a45ec 100644 --- a/rest/clients/airflow_client.py +++ b/rest/clients/airflow_client.py @@ -6,7 +6,7 @@ from urllib.parse import urljoin from core.logger import get_configured_logger from core.settings import settings - +from schemas.exceptions.base import ResourceNotFoundException class AirflowRestClient(requests.Session): def __init__(self, *args, **kwargs): @@ -150,6 +150,8 @@ def get_task_logs(self, dag_id: str, dag_run_id: str, task_id: str, task_try_num method='get', resource=resource, ) + if response.status_code == 404: + raise ResourceNotFoundException("Task result not found.") return response def get_task_result(self, dag_id: str, dag_run_id: str, task_id: str, task_try_number: int): @@ -159,6 +161,8 @@ def get_task_result(self, dag_id: str, dag_run_id: str, task_id: str, task_try_n method='get', resource=resource, ) + if response.status_code == 404: + raise ResourceNotFoundException("Task result not found.") if response.status_code != 200: raise BaseException("Error while trying to get task result base64_content") response_dict = ast.literal_eval(response.json()["value"])