From b9d00b9f5787187359c114a2facb144c297f3f22 Mon Sep 17 00:00:00 2001 From: pnoker Date: Wed, 29 Apr 2026 22:51:05 +0800 Subject: [PATCH] refactor(api): centralize axios calls into typed http helpers in api/common.ts --- src/api/attribute.ts | 26 +----- src/api/common.ts | 30 +++++++ src/api/device.ts | 161 +++------------------------------ src/api/dictionary.ts | 54 ++---------- src/api/driver.ts | 53 ++--------- src/api/info.ts | 99 ++------------------- src/api/point.ts | 181 ++++---------------------------------- src/api/profile.ts | 90 ++----------------- src/api/rule.ts | 15 +--- src/api/token.ts | 54 ++---------- src/config/axios/index.ts | 4 +- 11 files changed, 100 insertions(+), 667 deletions(-) create mode 100644 src/api/common.ts diff --git a/src/api/attribute.ts b/src/api/attribute.ts index 3769723a5..15a92fe8d 100644 --- a/src/api/attribute.ts +++ b/src/api/attribute.ts @@ -14,28 +14,8 @@ * limitations under the License. */ -import request from '@/config/axios'; +import { httpGet } from '@/api/common'; -/** - * Get driver attributes by driver ID - * - * @param id Driver ID - * @returns MyAxiosPromise - */ -export const getDriverAttributeByDriverId = (id: string) => - request({ - url: `api/v3/manager/driver_attribute/driver_id/${id}`, - method: 'get', - }); +export const getDriverAttributeByDriverId = (id: string) => httpGet(`api/v3/manager/driver_attribute/driver_id/${id}`); -/** - * Get point attributes by driver ID - * - * @param id Driver ID - * @returns MyAxiosPromise - */ -export const getPointAttributeByDriverId = (id: string) => - request({ - url: `api/v3/manager/point_attribute/driver_id/${id}`, - method: 'get', - }); +export const getPointAttributeByDriverId = (id: string) => httpGet(`api/v3/manager/point_attribute/driver_id/${id}`); diff --git a/src/api/common.ts b/src/api/common.ts new file mode 100644 index 000000000..c3267ab13 --- /dev/null +++ b/src/api/common.ts @@ -0,0 +1,30 @@ +/* + * Copyright 2016-present the IoT DC3 original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import request from '@/config/axios'; +import type { AxiosRequestConfig } from 'axios'; + +/** + * Shared HTTP helpers so every `src/api/*.ts` module stays a one-liner per + * endpoint. Keeps URL strings visible inline (grep-friendly) and lets the + * response interceptor do the payload unwrapping. + */ + +export const httpGet = (url: string, config?: AxiosRequestConfig) => + request({ ...config, url, method: 'get' }); + +export const httpPost = (url: string, data?: D, config?: AxiosRequestConfig) => + request({ ...config, url, method: 'post', data }); diff --git a/src/api/device.ts b/src/api/device.ts index 5dad81177..7267b8b3d 100644 --- a/src/api/device.ts +++ b/src/api/device.ts @@ -14,170 +14,37 @@ * limitations under the License. */ -import request from '@/config/axios'; +import { httpGet, httpPost } from '@/api/common'; -/** - * Add a new device - * - * @param device Device object - * @returns MyAxiosPromise - */ -export const addDevice = (device: any) => - request({ - url: `api/v3/manager/device/add`, - method: 'post', - data: device, - }); +export const addDevice = (device: any) => httpPost('api/v3/manager/device/add', device); -/** - * Delete a device - * - * @param id Device ID - * @returns MyAxiosPromise - */ -export const deleteDevice = (id: string) => - request({ - url: `api/v3/manager/device/delete/${id}`, - method: 'post', - }); +export const deleteDevice = (id: string) => httpPost(`api/v3/manager/device/delete/${id}`); -/** - * Update a device - * - * @param device Device object - * @returns MyAxiosPromise - */ -export const updateDevice = (device: any) => - request({ - url: `api/v3/manager/device/update`, - method: 'post', - data: device, - }); +export const updateDevice = (device: any) => httpPost('api/v3/manager/device/update', device); -/** - * Get device by ID - * - * @param id Device ID - * @returns MyAxiosPromise - */ -export const getDeviceById = (id: string) => - request({ - url: `api/v3/manager/device/id/${id}`, - method: 'get', - }); +export const getDeviceById = (id: string) => httpGet(`api/v3/manager/device/id/${id}`); -/** - * Get devices by IDs - * - * @param deviceIds Device ID array - * @returns MyAxiosPromise - */ -export const getDeviceByIds = (deviceIds: any) => - request({ - url: `api/v3/manager/device/ids`, - method: 'post', - data: deviceIds, - }); +export const getDeviceByIds = (deviceIds: any) => httpPost('api/v3/manager/device/ids', deviceIds); -/** - * Get devices by driver ID - * - * @param driverId Driver ID - * @returns MyAxiosPromise - */ -export const getDeviceByDriverId = (driverId: string) => - request({ - url: `api/v3/manager/device/driver_id/${driverId}`, - method: 'get', - }); +export const getDeviceByDriverId = (driverId: string) => httpGet(`api/v3/manager/device/driver_id/${driverId}`); -/** - * Get devices by profile ID - * - * @param profileId Profile ID - * @returns MyAxiosPromise - */ -export const getDeviceByProfileId = (profileId: string) => - request({ - url: `api/v3/manager/device/profile_id/${profileId}`, - method: 'get', - }); +export const getDeviceByProfileId = (profileId: string) => httpGet(`api/v3/manager/device/profile_id/${profileId}`); -/** - * Get device list with pagination - * - * @param device Device query parameters - * @returns MyAxiosPromise - */ -export const getDeviceList = (device: any) => - request({ - url: `api/v3/manager/device/list`, - method: 'post', - data: device, - }); +export const getDeviceList = (device: any) => httpPost('api/v3/manager/device/list', device); -/** - * Get device status with pagination - * - * @param device Device query parameters - * @returns MyAxiosPromise - */ -export const getDeviceStatus = (device: any) => - request({ - url: `api/v3/data/device/status/device`, - method: 'post', - data: device, - }); +export const getDeviceStatus = (device: any) => httpPost('api/v3/data/device/status/device', device); -/** - * Get device status by driver ID - * - * @param driverId Driver ID - * @returns MyAxiosPromise - */ export const getDeviceStatusByDriverId = (driverId: string) => - request({ - url: `api/v3/data/device/status/device/driver_id/${driverId}`, - method: 'get', - }); + httpGet(`api/v3/data/device/status/device/driver_id/${driverId}`); -/** - * Get device status by profile ID - * - * @param profileId Profile ID - * @returns MyAxiosPromise - */ export const getDeviceStatusByProfileId = (profileId: string) => - request({ - url: `api/v3/data/device/status/device/profile_id/${profileId}`, - method: 'get', - }); + httpGet(`api/v3/data/device/status/device/profile_id/${profileId}`); -/** - * Get device import template - * - * @param device Device query parameters - * @returns MyAxiosPromise - */ export const importDeviceTemplate = (device: any) => - request({ - url: `api/v3/manager/device/export/import_template`, - responseType: 'blob', - method: 'post', - data: device, - }); + httpPost('api/v3/manager/device/export/import_template', device, { responseType: 'blob' }); -/** - * Import devices from file - * - * @param device Device file data - * @returns MyAxiosPromise - */ export const importDevice = (device: any) => - request({ - url: `api/v3/manager/device/import`, - method: 'post', + httpPost('api/v3/manager/device/import', device, { timeout: 0, headers: { 'Content-Type': 'multipart/form-data' }, - data: device, }); diff --git a/src/api/dictionary.ts b/src/api/dictionary.ts index 1a62d5323..7870c972d 100644 --- a/src/api/dictionary.ts +++ b/src/api/dictionary.ts @@ -14,56 +14,12 @@ * limitations under the License. */ -import request from '@/config/axios'; +import { httpPost } from '@/api/common'; -/** - * Get driver dictionary - * - * @param dictionary Dictionary query parameters - * @returns MyAxiosPromise - */ -export const getDriverDictionary = (dictionary: any) => - request({ - url: `api/v3/manager/dictionary/driver`, - method: 'post', - data: dictionary, - }); +export const getDriverDictionary = (dictionary: any) => httpPost('api/v3/manager/dictionary/driver', dictionary); -/** - * Get device dictionary - * - * @param dictionary Dictionary query parameters - * @returns MyAxiosPromise - */ -export const getDeviceDictionary = (dictionary: any) => - request({ - url: `api/v3/manager/dictionary/device`, - method: 'post', - data: dictionary, - }); +export const getDeviceDictionary = (dictionary: any) => httpPost('api/v3/manager/dictionary/device', dictionary); -/** - * Get profile dictionary - * - * @param dictionary Dictionary query parameters - * @returns MyAxiosPromise - */ -export const getProfileDictionary = (dictionary: any) => - request({ - url: `api/v3/manager/dictionary/profile`, - method: 'post', - data: dictionary, - }); +export const getProfileDictionary = (dictionary: any) => httpPost('api/v3/manager/dictionary/profile', dictionary); -/** - * Get point dictionary - * - * @param dictionary Dictionary query parameters - * @returns MyAxiosPromise - */ -export const getPointDictionary = (dictionary: any) => - request({ - url: `api/v3/manager/dictionary/device_point`, - method: 'post', - data: dictionary, - }); +export const getPointDictionary = (dictionary: any) => httpPost('api/v3/manager/dictionary/device_point', dictionary); diff --git a/src/api/driver.ts b/src/api/driver.ts index 977e3fb77..05da8561f 100644 --- a/src/api/driver.ts +++ b/src/api/driver.ts @@ -14,55 +14,12 @@ * limitations under the License. */ -import request from '@/config/axios'; +import { httpGet, httpPost } from '@/api/common'; -/** - * Get driver by ID - * - * @param id Driver ID - * @returns MyAxiosPromise - */ -export const getDriverById = (id: string) => - request({ - url: `api/v3/manager/driver/id/${id}`, - method: 'get', - }); +export const getDriverById = (id: string) => httpGet(`api/v3/manager/driver/id/${id}`); -/** - * Get drivers by IDs - * - * @param driverIds Driver ID array - * @returns MyAxiosPromise - */ -export const getDriverByIds = (driverIds: any) => - request({ - url: `api/v3/manager/driver/ids`, - method: 'post', - data: driverIds, - }); +export const getDriverByIds = (driverIds: any) => httpPost('api/v3/manager/driver/ids', driverIds); -/** - * Get driver list with pagination - * - * @param driver Driver query parameters - * @returns MyAxiosPromise - */ -export const getDriverList = (driver: any) => - request({ - url: `api/v3/manager/driver/list`, - method: 'post', - data: driver, - }); +export const getDriverList = (driver: any) => httpPost('api/v3/manager/driver/list', driver); -/** - * Get driver status - * - * @param driver Driver query parameters - * @returns MyAxiosPromise - */ -export const getDriverStatus = (driver: any) => - request({ - url: `api/v3/data/driver/status/driver`, - method: 'post', - data: driver, - }); +export const getDriverStatus = (driver: any) => httpPost('api/v3/data/driver/status/driver', driver); diff --git a/src/api/info.ts b/src/api/info.ts index 64ff6d1f4..34d1bb9ce 100644 --- a/src/api/info.ts +++ b/src/api/info.ts @@ -14,106 +14,25 @@ * limitations under the License. */ -import request from '@/config/axios'; +import { httpGet, httpPost } from '@/api/common'; -/** - * Add driver configuration - * - * @param driverInfo Driver configuration object - * @returns MyAxiosPromise - */ -export const addDriverInfo = (driverInfo: any) => - request({ - url: `api/v3/manager/driver_attribute_config/add`, - method: 'post', - data: driverInfo, - }); +export const addDriverInfo = (driverInfo: any) => httpPost('api/v3/manager/driver_attribute_config/add', driverInfo); -/** - * Update driver configuration - * - * @param driverInfo Driver configuration object - * @returns MyAxiosPromise - */ export const updateDriverInfo = (driverInfo: any) => - request({ - url: `api/v3/manager/driver_attribute_config/update`, - method: 'post', - data: driverInfo, - }); + httpPost('api/v3/manager/driver_attribute_config/update', driverInfo); -/** - * Get driver configuration by device ID and attribute ID - * - * @param deviceId Device ID - * @param attributeId Attribute ID - * @returns MyAxiosPromise - */ export const getDriverInfoByDeviceIdAndAttributeId = (deviceId: string, attributeId: string) => - request({ - url: `api/v3/manager/driver_attribute_config/device_id/${deviceId}/attribute_id/${attributeId}`, - method: 'get', - }); + httpGet(`api/v3/manager/driver_attribute_config/device_id/${deviceId}/attribute_id/${attributeId}`); -/** - * Get driver configuration by device ID - * - * @param deviceId Device ID - * @returns MyAxiosPromise - */ export const getDriverInfoByDeviceId = (deviceId: string) => - request({ - url: `api/v3/manager/driver_attribute_config/device_id/${deviceId}`, - method: 'get', - }); + httpGet(`api/v3/manager/driver_attribute_config/device_id/${deviceId}`); -/** - * Add point configuration - * - * @param pointInfo Point configuration object - * @returns MyAxiosPromise - */ -export const addPointInfo = (pointInfo: any) => - request({ - url: `api/v3/manager/point_attribute_config/add`, - method: 'post', - data: pointInfo, - }); +export const addPointInfo = (pointInfo: any) => httpPost('api/v3/manager/point_attribute_config/add', pointInfo); -/** - * Update point configuration - * - * @param pointInfo Point configuration object - * @returns MyAxiosPromise - */ -export const updatePointInfo = (pointInfo: any) => - request({ - url: `api/v3/manager/point_attribute_config/update`, - method: 'post', - data: pointInfo, - }); +export const updatePointInfo = (pointInfo: any) => httpPost('api/v3/manager/point_attribute_config/update', pointInfo); -/** - * Get point configuration by device ID and point ID - * - * @param deviceId Device ID - * @param pointId Point ID - * @returns MyAxiosPromise - */ export const getPointInfoByDeviceIdAndPointId = (deviceId: string, pointId: string) => - request({ - url: `api/v3/manager/point_attribute_config/device_id/${deviceId}/point_id/${pointId}`, - method: 'get', - }); + httpGet(`api/v3/manager/point_attribute_config/device_id/${deviceId}/point_id/${pointId}`); -/** - * Get point configuration by device ID - * - * @param deviceId Device ID - * @returns MyAxiosPromise - */ export const getPointInfoByDeviceId = (deviceId: string) => - request({ - url: `api/v3/manager/point_attribute_config/device_id/${deviceId}`, - method: 'get', - }); + httpGet(`api/v3/manager/point_attribute_config/device_id/${deviceId}`); diff --git a/src/api/point.ts b/src/api/point.ts index 29b021462..02a908e96 100644 --- a/src/api/point.ts +++ b/src/api/point.ts @@ -14,186 +14,37 @@ * limitations under the License. */ -import request from '@/config/axios'; +import { httpGet, httpPost } from '@/api/common'; -/** - * Add a new point - * - * @param point Point object - * @returns MyAxiosPromise - */ -export const pointAddApi = (point: any) => - request({ - url: `api/v3/manager/point/add`, - method: 'post', - data: point, - }); +export const pointAddApi = (point: any) => httpPost('api/v3/manager/point/add', point); -/** - * Delete a point - * - * @param id Point ID - * @returns MyAxiosPromise - */ -export const pointDeleteApi = (id: string) => - request({ - url: `api/v3/manager/point/delete/${id}`, - method: 'post', - }); +export const pointDeleteApi = (id: string) => httpPost(`api/v3/manager/point/delete/${id}`); -/** - * Update a point - * - * @param point Point object - * @returns MyAxiosPromise - */ -export const getPointUpdate = (point: any) => - request({ - url: `api/v3/manager/point/update`, - method: 'post', - data: point, - }); +export const getPointUpdate = (point: any) => httpPost('api/v3/manager/point/update', point); -/** - * Get point by ID - * - * @param id Point ID - * @returns MyAxiosPromise - */ -export const getPointById = (id: string) => - request({ - url: `api/v3/manager/point/id/${id}`, - method: 'get', - }); +export const getPointById = (id: string) => httpGet(`api/v3/manager/point/id/${id}`); -/** - * Get points by IDs - * - * @param pointIds Point ID array - * @returns MyAxiosPromise - */ -export const getPointByIds = (pointIds: any) => - request({ - url: `api/v3/manager/point/ids`, - method: 'post', - data: pointIds, - }); +export const getPointByIds = (pointIds: any) => httpPost('api/v3/manager/point/ids', pointIds); -/** - * Get point list with pagination and fuzzy search - * - * @param point Point query parameters - * @returns MyAxiosPromise - */ -export const getPointList = (point: any) => - request({ - url: `api/v3/manager/point/list`, - method: 'post', - data: point, - }); +export const getPointList = (point: any) => httpPost('api/v3/manager/point/list', point); -/** - * Get point units by point IDs - * - * @param pointIds Point ID array - * @returns MyAxiosPromise - */ -export const getPointUnit = (pointIds: any) => - request({ - url: `api/v3/manager/point/unit`, - method: 'post', - data: pointIds, - }); +export const getPointUnit = (pointIds: any) => httpPost('api/v3/manager/point/unit', pointIds); -/** - * Get points by profile ID - * - * @param profileId Profile ID - * @returns MyAxiosPromise - */ -export const getPointByProfileId = (profileId: string) => - request({ - url: `api/v3/manager/point/profile_id/${profileId}`, - method: 'get', - }); +export const getPointByProfileId = (profileId: string) => httpGet(`api/v3/manager/point/profile_id/${profileId}`); -/** - * Get points by device ID - * - * @param deviceId Device ID - * @returns MyAxiosPromise - */ -export const getPointByDeviceId = (deviceId: string) => - request({ - url: `api/v3/manager/point/device_id/${deviceId}`, - method: 'get', - }); +export const getPointByDeviceId = (deviceId: string) => httpGet(`api/v3/manager/point/device_id/${deviceId}`); -/** - * Get latest point values with pagination - * - * @param pointValue Point value query parameters - * @returns MyAxiosPromise - */ -export const getPointValueLatest = (pointValue: any) => - request({ - url: `api/v3/data/point_value/latest`, - method: 'post', - data: pointValue, - }); +export const getPointValueLatest = (pointValue: any) => httpPost('api/v3/data/point_value/latest', pointValue); -/** - * Get point values with pagination - * - * @param pointValue Point value query parameters - * @returns MyAxiosPromise - */ -export const getPointValueList = (pointValue: any) => - request({ - url: `api/v3/data/point_value/list`, - method: 'post', - data: pointValue, - }); +export const getPointValueList = (pointValue: any) => httpPost('api/v3/data/point_value/list', pointValue); -/** - * Get point value history - * - * @param deviceId Device ID - * @param pointId Point ID - * @param count Number of records to retrieve - * @returns MyAxiosPromise - */ export const getPointValueHistory = (deviceId: number, pointId: number, count: number = 100) => - request({ - url: `api/v3/data/point_value/history/device_id/${deviceId}/point_id/${pointId}`, - method: 'get', - params: { - count, - }, + httpGet(`api/v3/data/point_value/history/device_id/${deviceId}/point_id/${pointId}`, { + params: { count }, }); -/** - * Read point value - * - * @param pointValueReadVO Point value read object - * @returns MyAxiosPromise - */ export const readPointValue = (pointValueReadVO: any) => - request({ - url: `api/v3/data/point_value_command/read`, - method: 'post', - data: pointValueReadVO, - }); + httpPost('api/v3/data/point_value_command/read', pointValueReadVO); -/** - * Write point value - * - * @param pointValueWriteVO Point value write object - * @returns MyAxiosPromise - */ export const writePointValue = (pointValueWriteVO: any) => - request({ - url: `api/v3/data/point_value_command/write`, - method: 'post', - data: pointValueWriteVO, - }); + httpPost('api/v3/data/point_value_command/write', pointValueWriteVO); diff --git a/src/api/profile.ts b/src/api/profile.ts index cfb3b45b0..25f60401c 100644 --- a/src/api/profile.ts +++ b/src/api/profile.ts @@ -14,92 +14,18 @@ * limitations under the License. */ -import request from '@/config/axios'; +import { httpGet, httpPost } from '@/api/common'; -/** - * Add a new profile - * - * @param profile Profile object - * @returns MyAxiosPromise - */ -export const addProfile = (profile: any) => - request({ - url: `api/v3/manager/profile/add`, - method: 'post', - data: profile, - }); +export const addProfile = (profile: any) => httpPost('api/v3/manager/profile/add', profile); -/** - * Delete a profile - * - * @param id Profile ID - * @returns MyAxiosPromise - */ -export const deleteProfile = (id: string) => - request({ - url: `api/v3/manager/profile/delete/${id}`, - method: 'post', - }); +export const deleteProfile = (id: string) => httpPost(`api/v3/manager/profile/delete/${id}`); -/** - * Update a profile - * - * @param profile Profile object - * @returns MyAxiosPromise - */ -export const updateProfile = (profile: any) => - request({ - url: `api/v3/manager/profile/update`, - method: 'post', - data: profile, - }); +export const updateProfile = (profile: any) => httpPost('api/v3/manager/profile/update', profile); -/** - * Get profile by ID - * - * @param id Profile ID - * @returns MyAxiosPromise - */ -export const getProfileById = (id: string) => - request({ - url: `api/v3/manager/profile/id/${id}`, - method: 'get', - }); +export const getProfileById = (id: string) => httpGet(`api/v3/manager/profile/id/${id}`); -/** - * Get profiles by IDs - * - * @param profileIds Profile ID array - * @returns MyAxiosPromise - */ -export const getProfileByIds = (profileIds: any) => - request({ - url: `api/v3/manager/profile/ids`, - method: 'post', - data: profileIds, - }); +export const getProfileByIds = (profileIds: any) => httpPost('api/v3/manager/profile/ids', profileIds); -/** - * Get profile by device ID - * - * @param deviceId Device ID - * @returns MyAxiosPromise - */ -export const getProfileByDeviceId = (deviceId: string) => - request({ - url: `api/v3/manager/profile/device_id/${deviceId}`, - method: 'get', - }); +export const getProfileByDeviceId = (deviceId: string) => httpGet(`api/v3/manager/profile/device_id/${deviceId}`); -/** - * Get profile list with pagination - * - * @param profile Profile query parameters - * @returns MyAxiosPromise - */ -export const getProfileList = (profile: any) => - request({ - url: `api/v3/manager/profile/list`, - method: 'post', - data: profile, - }); +export const getProfileList = (profile: any) => httpPost('api/v3/manager/profile/list', profile); diff --git a/src/api/rule.ts b/src/api/rule.ts index ca5174202..bc76e2343 100644 --- a/src/api/rule.ts +++ b/src/api/rule.ts @@ -14,17 +14,6 @@ * limitations under the License. */ -import request from '@/config/axios'; +import { httpPost } from '@/api/common'; -/** - * Get flows list - * - * @param flowsQuery Flows query parameters - * @returns MyAxiosPromise - */ -export const getFlowsList = (flowsQuery: any) => - request({ - url: 'api/v3/manager/ruleengine/flowsList', - method: 'post', - data: flowsQuery, - }); +export const getFlowsList = (flowsQuery: any) => httpPost('api/v3/manager/ruleengine/flowsList', flowsQuery); diff --git a/src/api/token.ts b/src/api/token.ts index e3857ad3c..5c47e4b49 100644 --- a/src/api/token.ts +++ b/src/api/token.ts @@ -14,57 +14,13 @@ * limitations under the License. */ -import request from '@/config/axios'; +import { httpPost } from '@/api/common'; import type { Login } from '@/config/entity'; -/** - * Generate salt for password encryption - * - * @param login Login object - * @returns MyAxiosPromise - */ -export const generateSalt = (login: Login) => - request({ - url: `api/v3/auth/token/salt`, - method: 'post', - data: login, - }); +export const generateSalt = (login: Login) => httpPost('api/v3/auth/token/salt', login); -/** - * Generate authentication token (login) - * - * @param login Login object - * @returns MyAxiosPromise - */ -export const generateToken = (login: Login) => - request({ - url: `api/v3/auth/token/generate`, - method: 'post', - data: login, - }); +export const generateToken = (login: Login) => httpPost('api/v3/auth/token/generate', login); -/** - * Cancel authentication token (logout) - * - * @param login Login object - * @returns MyAxiosPromise - */ -export const cancelToken = (login: Login) => - request({ - url: `api/v3/auth/token/cancel`, - method: 'post', - data: login, - }); +export const cancelToken = (login: Login) => httpPost('api/v3/auth/token/cancel', login); -/** - * Check if token is valid - * - * @param login Login object - * @returns MyAxiosPromise - */ -export const checkTokenValid = (login: Login) => - request({ - url: `api/v3/auth/token/check`, - method: 'post', - data: login, - }); +export const checkTokenValid = (login: Login) => httpPost('api/v3/auth/token/check', login); diff --git a/src/config/axios/index.ts b/src/config/axios/index.ts index 7120ca4f5..7d367f6f8 100644 --- a/src/config/axios/index.ts +++ b/src/config/axios/index.ts @@ -134,7 +134,9 @@ request.interceptors.response.use( } else { failMessage(ERROR_MESSAGES.REQUEST_ERROR, response.data.code, response.data); } - return Promise.reject(); + // Reject with the server payload so callers can inspect code/message if needed. + // Existing no-op `.catch(() => {})` sites remain valid because they ignore the argument. + return Promise.reject(response.data ?? { status, message: 'Request failed' }); }, (error: AxiosError) => { return Promise.reject(error);