Skip to content

Commit

Permalink
refactor interceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
jsartisan committed Nov 26, 2024
1 parent d8244c9 commit c4321f7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
13 changes: 13 additions & 0 deletions app/client/src/api/interceptors/request/addVersionHeader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { InternalAxiosRequestConfig } from "axios";

export const addVersionHeader = (
config: InternalAxiosRequestConfig,
options: { version: string },
) => {
const { version } = options;

config.headers = config.headers || {};
config.headers["X-Appsmith-Version"] = version;

return config;
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import getQueryParamsObject from "utils/getQueryParamsObject";
import { addRequestedByHeader } from "./addRequestedByHeader";
import { increaseGitApiTimeout } from "./increaseGitApiTimeout";
import { getCurrentGitBranch } from "selectors/gitSyncSelectors";
import { addVersionHeader as _addVersionHeader } from "./addVersionHeader";
import { getCurrentEnvironmentId } from "ee/selectors/environmentSelectors";
import { addGitBranchHeader as _addGitBranchHeader } from "./addGitBranchHeader";
import { addPerformanceMonitoringHeaders } from "./addPerformanceMonitoringHeaders";
Expand Down Expand Up @@ -50,10 +51,10 @@ const addAnonymousUserIdHeader = (config: InternalAxiosRequestConfig) => {
};

const addVersionHeader = (config: InternalAxiosRequestConfig) => {
config.headers = config.headers || {};
config.headers["X-Appsmith-Version"] = getAppsmithConfigs().appVersion.id;
const appsmithConfig = getAppsmithConfigs();
const version = appsmithConfig.appVersion.id;

return config;
return _addVersionHeader(config, { version });
};

export const apiRequestInterceptor = (config: InternalAxiosRequestConfig) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export { handle413Error } from "./handle413Error";
export { handleBadRequestError } from "./handleBadRequestError";
export { handleServerError } from "./handleServerError";
export { handleCancelError } from "./handleCancelError";
export { handleOfflineError } from "./handleOfflineError";
export { handleTimeoutError } from "./handleTimeoutError";
export { handleNotFoundError } from "./handleNotFoundError";
export { handleBadRequestError } from "./handleBadRequestError";
export { handleUnauthorizedError } from "./handleUnauthorizedError";
export { handleExecuteActionError } from "./handleExecuteActionError";
export { handleMissingResponseMeta } from "./handleMissingResponseMeta";

0 comments on commit c4321f7

Please sign in to comment.