Skip to content

Scheduling infrastructure for absolutely everyone.

chore: better error messages (#26890)

Rajiv Sahal568d9de160b2
diff --git a/apps/api/v2/src/filters/trpc-exception.filter.ts b/apps/api/v2/src/filters/trpc-exception.filter.ts
index 02bf3aab2df..8eb217ad238 100644
--- a/apps/api/v2/src/filters/trpc-exception.filter.ts
+++ b/apps/api/v2/src/filters/trpc-exception.filter.ts
@@ -116,7 +116,7 @@ export class TRPCExceptionFilter implements ExceptionFilter {
};
const statusCode = errorDefinition.statusCode;
- const errorMessage = errorDefinition.message;
+ const errorMessage = exception.message || errorDefinition.message;
const requestId = request.headers["X-Request-Id"] ?? "unknown-request-id";
response.setHeader("X-Request-Id", requestId.toString());
diff --git a/packages/platform/atoms/event-types/hooks/useAtomUpdateEventType.ts b/packages/platform/atoms/event-types/hooks/useAtomUpdateEventType.ts
index 2aebcb6c187..bd598ca0452 100644
--- a/packages/platform/atoms/event-types/hooks/useAtomUpdateEventType.ts
+++ b/packages/platform/atoms/event-types/hooks/useAtomUpdateEventType.ts
@@ -1,8 +1,9 @@
import { useMutation } from "@tanstack/react-query";
+import type { AxiosError } from "axios";
import type { EventTypeUpdateInput } from "@calcom/features/eventtypes/lib/types";
import { V2_ENDPOINTS, SUCCESS_STATUS } from "@calcom/platform-constants";
-import type { ApiResponse, ApiSuccessResponse } from "@calcom/platform-types";
+import type { ApiErrorResponse, ApiResponse, ApiSuccessResponse } from "@calcom/platform-types";
import type { EventType } from "@calcom/prisma/client";
import { useAtomsContext } from "../../hooks/useAtomsContext";
@@ -32,19 +33,26 @@ export const useAtomUpdateEventType = ({
onSuccess,
onError,
onSettled,
- mutationFn: (data: EventTypeUpdateInput) => {
+ mutationFn: async (data: EventTypeUpdateInput) => {
if (!data.id) throw new Error("Event type id is required");
let pathname = `/atoms/${V2_ENDPOINTS.eventTypes}/${data.id}`;
if (teamId) {
pathname = `/atoms/organizations/${organizationId}/teams/${teamId}/${V2_ENDPOINTS.eventTypes}/${data.id}`;
}
- return http?.patch<ApiResponse<EventType>>(pathname, data).then((res) => {
- if (res.data.status === SUCCESS_STATUS) {
+ try {
+ const res = await http?.patch<ApiResponse<EventType>>(pathname, data);
+ if (res?.data.status === SUCCESS_STATUS) {
return (res.data as ApiSuccessResponse<EventType>).data;
}
- throw new Error(res.data.error.message);
- });
+ throw new Error(res?.data.error.message);
+ } catch (err) {
+ const axiosError = err as AxiosError<ApiErrorResponse>;
+ if (axiosError.response?.data?.error?.message) {
+ throw new Error(axiosError.response.data.error.message);
+ }
+ throw err;
+ }
},
});
};