Refactored UI endpoint usage
This commit is contained in:
@@ -172,22 +172,20 @@ export function getUserSyncRecord(): UserSyncRecord | null {
|
||||
}
|
||||
|
||||
export const USER_SYNC_CANDIDATE_ENDPOINTS = [
|
||||
'/v1/api/users/sync',
|
||||
'/v1/api/integration/sync',
|
||||
'/v1/api/users/sync',
|
||||
'/v1/api/user/sync',
|
||||
];
|
||||
|
||||
/**
|
||||
* Determines whether a given URL or request path targets a user sync endpoint.
|
||||
* This is used to differentiate user sync / lockout lifecycle calls from regular
|
||||
* business working endpoints, ensuring established call priority and subordination.
|
||||
*/
|
||||
export function isUserSyncEndpoint(url?: string): boolean {
|
||||
if (!url) return false;
|
||||
const clean = url.toLowerCase().split('?')[0];
|
||||
return (
|
||||
clean.includes('/users/sync') ||
|
||||
clean.includes('/integration/sync') ||
|
||||
clean.includes('/users/sync') ||
|
||||
clean.includes('/user/sync') ||
|
||||
clean.endsWith('/sync') ||
|
||||
clean === '/sync'
|
||||
@@ -195,9 +193,7 @@ export function isUserSyncEndpoint(url?: string): boolean {
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the backend user sync request.
|
||||
* Tries the primary '/v1/api/users/sync' endpoint, falling back to
|
||||
* '/v1/api/integration/sync' or '/v1/api/user/sync' if needed.
|
||||
* Executes the backend user sync request across available candidate endpoints.
|
||||
*/
|
||||
async function executeBackendSync(
|
||||
userSub?: string,
|
||||
@@ -218,20 +214,33 @@ async function executeBackendSync(
|
||||
|
||||
for (const endpoint of candidateEndpoints) {
|
||||
try {
|
||||
const res = await apiClient.post(endpoint, payload);
|
||||
return { endpoint, data: res.data };
|
||||
let res;
|
||||
if (endpoint === '/v1/api/integration/sync') {
|
||||
try {
|
||||
res = await apiClient.post(endpoint, payload);
|
||||
} catch (postErr: any) {
|
||||
const errStatus = postErr?.response?.status;
|
||||
if (errStatus === 400 || errStatus === 415 || errStatus === 422) {
|
||||
res = await apiClient.post(endpoint, {});
|
||||
} else {
|
||||
throw postErr;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
res = await apiClient.post(endpoint, payload);
|
||||
}
|
||||
return { endpoint, data: res?.data };
|
||||
} catch (err: any) {
|
||||
lastError = err;
|
||||
const status = err?.response?.status;
|
||||
|
||||
// 1. If HTTP 401 Unauthorized: token expired or invalid, fail fast
|
||||
// Fail fast on token expiration/invalid
|
||||
if (status === 401) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
// 2. If HTTP 403 Forbidden, 423 Locked, or non-404 client error:
|
||||
// The endpoint is valid, but the user is blocked/disabled/not activated by the administrator.
|
||||
if (status === 403 || status === 423 || (status && status >= 400 && status !== 404 && status !== 405)) {
|
||||
// User blocked or pending activation
|
||||
if (status === 403 || status === 423) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user