Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: optimize request error (#16674)
ecmadaoc51658e99137
diff --git a/backend/api/v1/auth_service.go b/backend/api/v1/auth_service.goindex 0daf07a450..c8480171fa 100644--- a/backend/api/v1/auth_service.go+++ b/backend/api/v1/auth_service.go@@ -94,7 +94,7 @@ func (s *AuthService) Login(ctx context.Context, req *connect.Request[v1pb.Login}user, err := s.store.GetUserByID(ctx, userID)if err != nil {- return nil, err+ return nil, connect.NewError(connect.CodeInternal, errors.Wrapf(err, "failed to find user, error"))}if user == nil {return nil, invalidUserOrPasswordErrordiff --git a/backend/api/v1/user_service.go b/backend/api/v1/user_service.goindex eee0e6b53d..a07de81e1e 100644--- a/backend/api/v1/user_service.go+++ b/backend/api/v1/user_service.go@@ -841,7 +841,7 @@ func validateEmailWithDomains(ctx context.Context, licenseService *enterprise.Li// Check if the email is valid.if err := validateEmail(email); err != nil {- return err+ return connect.NewError(connect.CodeInvalidArgument, errors.Errorf("invalid email: %v", err.Error()))}// Domain restrictions are not applied to service account.if isServiceAccount {@@ -857,7 +857,7 @@ func validateEmailWithDomains(ctx context.Context, licenseService *enterprise.Li}}if !ok {- return errors.Errorf("email %q does not belong to domains %v", email, allowedDomains)+ return connect.NewError(connect.CodeInvalidArgument, errors.Errorf("email %q does not belong to domains %v", email, allowedDomains))}}return nildiff --git a/frontend/src/App.vue b/frontend/src/App.vueindex ccb1c36e0a..91fc6ca651 100644--- a/frontend/src/App.vue+++ b/frontend/src/App.vue@@ -25,6 +25,7 @@</template><script lang="ts" setup>+import { Code, ConnectError } from "@connectrpc/connect";import { cloneDeep, isEqual } from "lodash-es";import {NConfigProvider,@@ -67,8 +68,17 @@ onErrorCaptured((error: any /* , _, info */) => {(error instanceof ServerError || error instanceof ClientError) &&Object.values(Status).includes(error.code)) {+ return;// Ignored: we will handle request errors in the error handler middleware of nice-grpc-web.- } else if (!error.response) {+ }+ if (+ error instanceof ConnectError &&+ Object.values(Code).includes(error.code)+ ) {+ return;+ }++ if (!error.response) {notificationStore.pushNotification({module: "bytebase",style: "CRITICAL",diff --git a/frontend/src/grpcweb/middlewares/authInterceptorMiddleware.ts b/frontend/src/grpcweb/middlewares/authInterceptorMiddleware.tsindex ec72dc5776..3c166f0869 100644--- a/frontend/src/grpcweb/middlewares/authInterceptorMiddleware.ts+++ b/frontend/src/grpcweb/middlewares/authInterceptorMiddleware.ts@@ -82,6 +82,7 @@ export const authInterceptor: Interceptor = (next) => async (req) => {const resp = await next(req);return resp;} catch (error) {+ const authStore = useAuthStore();// If silent is set to true, will NOT show redirect to other pages(e.g., 403, sign in page).const silent = req.contextValues.get(silentContextKey);const ignoredCodes = req.contextValues.get(ignoredCodesContextKey);@@ -91,17 +92,19 @@ export const authInterceptor: Interceptor = (next) => async (req) => {if (ignoredCodes?.includes(code)) {// omit specified errors} else {- if (code === Code.Unauthenticated) {+ if (code === Code.Unauthenticated && req.method.name !== "Login") {// Skip show login modal when the request is to get current user.// When receiving 401 and is returned by our server, it means the current// login user's token becomes invalid. Thus we force the user to login again.- useAuthStore().unauthenticatedOccurred = true;- pushNotification({- module: "bytebase",- style: "WARN",- title: t("auth.token-expired-title"),- description: t("auth.token-expired-description"),- });+ authStore.unauthenticatedOccurred = true;+ if (authStore.isLoggedIn) {+ pushNotification({+ module: "bytebase",+ style: "WARN",+ title: t("auth.token-expired-title"),+ description: t("auth.token-expired-description"),+ });+ }} else if (code === Code.PermissionDenied) {// Jump to 403 pagerouter.push({ name: "error.403" });diff --git a/frontend/src/store/modules/v1/auth.ts b/frontend/src/store/modules/v1/auth.tsindex 331ad69ed6..bfbbc1cc0c 100644--- a/frontend/src/store/modules/v1/auth.ts+++ b/frontend/src/store/modules/v1/auth.ts@@ -1,9 +1,12 @@import { create } from "@bufbuild/protobuf";+import { createContextValues } from "@connectrpc/connect";+import { Code } from "@connectrpc/connect";import { useLocalStorage } from "@vueuse/core";import { uniqueId } from "lodash-es";import { defineStore } from "pinia";import { computed, ref } from "vue";import { authServiceClientConnect, userServiceClientConnect } from "@/grpcweb";+import { ignoredCodesContextKey } from "@/grpcweb/context-key";import { router } from "@/router";import {AUTH_SIGNIN_MODULE,@@ -73,7 +76,11 @@ export const useAuthStore = defineStore("auth_v1", () => {};const login = async (request: LoginRequest, redirect: string = "") => {- const resp = await authServiceClientConnect.login(request);+ const resp = await authServiceClientConnect.login(request, {+ contextValues: createContextValues().set(ignoredCodesContextKey, [+ Code.NotFound,+ ]),+ });const redirectUrl = redirect || getRedirectQuery() || "/";if (resp.mfaTempToken) {unauthenticatedOccurred.value = false;