From 06b38f395c0c416c7064a1609b0f77f72ecc4b8b Mon Sep 17 00:00:00 2001 From: Kenta Kozuka Date: Fri, 8 Sep 2023 15:12:57 +0900 Subject: [PATCH] Display MySQL user defined error of piped, command, and application (#4597) Signed-off-by: Kenta Kozuka --- pkg/app/server/grpcapi/grpcapi.go | 2 +- .../application-detail/index.tsx | 6 ++++-- .../add-application-drawer/index.tsx | 14 +++++++++----- .../components/settings-page/api-key/index.tsx | 1 - .../piped/components/add-piped-dialog/index.tsx | 17 ++++++++++------- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/pkg/app/server/grpcapi/grpcapi.go b/pkg/app/server/grpcapi/grpcapi.go index 9b65f0ad6e..420c6887b6 100644 --- a/pkg/app/server/grpcapi/grpcapi.go +++ b/pkg/app/server/grpcapi/grpcapi.go @@ -101,7 +101,7 @@ func getCommand(ctx context.Context, store commandstore.Store, id string, logger func addCommand(ctx context.Context, store commandstore.Store, cmd *model.Command, logger *zap.Logger) error { if err := store.AddCommand(ctx, cmd); err != nil { logger.Error("failed to create command", zap.Error(err)) - return status.Error(codes.Internal, "Failed to create command") + return gRPCStoreError(err, "create command") } return nil } diff --git a/web/src/components/application-detail-page/application-detail/index.tsx b/web/src/components/application-detail-page/application-detail/index.tsx index 7291335e6e..4de10548c3 100644 --- a/web/src/components/application-detail-page/application-detail/index.tsx +++ b/web/src/components/application-detail-page/application-detail/index.tsx @@ -22,7 +22,7 @@ import { SplitButton } from "~/components/split-button"; import { APPLICATION_KIND_TEXT } from "~/constants/application-kind"; import { PAGE_PATH_DEPLOYMENTS } from "~/constants/path"; import { UI_TEXT_REFRESH } from "~/constants/ui-text"; -import { useAppDispatch, useAppSelector } from "~/hooks/redux"; +import { unwrapResult, useAppDispatch, useAppSelector } from "~/hooks/redux"; import { Application, ApplicationDeploymentReference, @@ -238,7 +238,9 @@ export const ApplicationDetail: FC = memo( applicationId: app.id, syncStrategy: syncStrategyByIndex[index], }) - ); + ) + .then(unwrapResult) + .catch(() => undefined); } }; diff --git a/web/src/components/applications-page/add-application-drawer/index.tsx b/web/src/components/applications-page/add-application-drawer/index.tsx index 423f028178..d8e10a801a 100644 --- a/web/src/components/applications-page/add-application-drawer/index.tsx +++ b/web/src/components/applications-page/add-application-drawer/index.tsx @@ -9,7 +9,7 @@ import { import { useFormik } from "formik"; import { FC, memo, useCallback, useState } from "react"; import { UI_TEXT_CANCEL, UI_TEXT_DISCARD } from "~/constants/ui-text"; -import { useAppDispatch, useAppSelector } from "~/hooks/redux"; +import { unwrapResult, useAppDispatch, useAppSelector } from "~/hooks/redux"; import { addApplication } from "~/modules/applications"; import { selectProjectName } from "~/modules/me"; import { @@ -42,10 +42,14 @@ export const AddApplicationDrawer: FC = memo( validationSchema, enableReinitialize: true, async onSubmit(values) { - await dispatch(addApplication(values)); - onAdded(); - onClose(); - formik.resetForm(); + await dispatch(addApplication(values)) + .then(unwrapResult) + .then(() => { + onAdded(); + onClose(); + formik.resetForm(); + }) + .catch(() => undefined); }, }); diff --git a/web/src/components/settings-page/api-key/index.tsx b/web/src/components/settings-page/api-key/index.tsx index 28e007cf27..0141a6fd7e 100644 --- a/web/src/components/settings-page/api-key/index.tsx +++ b/web/src/components/settings-page/api-key/index.tsx @@ -99,7 +99,6 @@ export const APIKeyPage: FC = memo(function APIKeyPage() { dispatch(generateAPIKey(values)) .then(unwrapResult) .then(() => { - console.log("handleSubmit.then"); dispatch(fetchAPIKeys({ enabled: true })); dispatch( addToast({ message: GENERATE_API_KEY_SUCCESS, severity: "success" }) diff --git a/web/src/components/settings-page/piped/components/add-piped-dialog/index.tsx b/web/src/components/settings-page/piped/components/add-piped-dialog/index.tsx index 578a53e8c7..c5d25411d4 100644 --- a/web/src/components/settings-page/piped/components/add-piped-dialog/index.tsx +++ b/web/src/components/settings-page/piped/components/add-piped-dialog/index.tsx @@ -2,7 +2,7 @@ import { Dialog } from "@material-ui/core"; import { useFormik } from "formik"; import { FC, memo, useCallback } from "react"; import { ADD_PIPED_SUCCESS } from "~/constants/toast-text"; -import { useAppDispatch, useAppSelector } from "~/hooks/redux"; +import { unwrapResult, useAppDispatch, useAppSelector } from "~/hooks/redux"; import { selectProjectName } from "~/modules/me"; import { addPiped } from "~/modules/pipeds"; import { addToast } from "~/modules/toasts"; @@ -23,12 +23,15 @@ export const AddPipedDialog: FC = memo( validationSchema, validateOnMount: true, async onSubmit(values) { - await dispatch(addPiped(values)).then(() => { - dispatch( - addToast({ message: ADD_PIPED_SUCCESS, severity: "success" }) - ); - onClose(); - }); + await dispatch(addPiped(values)) + .then(unwrapResult) + .then(() => { + dispatch( + addToast({ message: ADD_PIPED_SUCCESS, severity: "success" }) + ); + onClose(); + }) + .catch(() => undefined); }, });