hl-core 0.0.10-beta.82 → 0.0.10-beta.83

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,23 @@
1
1
  import { AxiosError, type AxiosInstance, type InternalAxiosRequestConfig, isAxiosError } from 'axios';
2
+
3
+ const INTERCEPTOR_HANDLED_STATUSES = new Set([401, 403, 404, 413, 500]);
4
+
5
+ function markErrorAsHandled(err: unknown, status?: number): void {
6
+ if (typeof status === 'number' && !INTERCEPTOR_HANDLED_STATUSES.has(status)) return;
7
+
8
+ const axiosError = err as { config?: Record<string, unknown>; handledByInterceptor?: boolean; handledStatus?: number };
9
+ axiosError.handledByInterceptor = true;
10
+ if (typeof status === 'number') {
11
+ axiosError.handledStatus = status;
12
+ }
13
+
14
+ if (axiosError.config) {
15
+ axiosError.config.handledByInterceptor = true;
16
+ if (typeof status === 'number') {
17
+ axiosError.config.handledStatus = status;
18
+ }
19
+ }
20
+ }
2
21
  /**
3
22
  * Обновляет baseURL в зависимости от текущего хоста
4
23
  */
@@ -118,6 +137,7 @@ export default function setupInterceptors(axios: AxiosInstance): void {
118
137
 
119
138
  // 1) Не-Axios ошибка (например, thrown Error)
120
139
  if (!isAxiosError(err)) {
140
+ markErrorAsHandled(err);
121
141
  showToaster('error', appContextStore.t('toaster.unknownError'), 5000);
122
142
  return Promise.reject(err);
123
143
  }
@@ -126,6 +146,7 @@ export default function setupInterceptors(axios: AxiosInstance): void {
126
146
 
127
147
  // 2) Нет ответа вообще (timeout, сеть, CORS)
128
148
  if (!response) {
149
+ markErrorAsHandled(err);
129
150
  const isTimeout = code === 'ECONNABORTED' || /timeout/i.test(String(message));
130
151
  showToaster('error', isTimeout ? appContextStore.t('toaster.timeout') : appContextStore.t('toaster.networkError'), 5000);
131
152
  return Promise.reject(err);
@@ -137,12 +158,14 @@ export default function setupInterceptors(axios: AxiosInstance): void {
137
158
 
138
159
  // 3) 401 — простая обработка, показываем ошибку
139
160
  if (status === 401) {
161
+ markErrorAsHandled(err, status);
140
162
  showToaster('error', appContextStore.t('error.401'), 5000);
141
163
  return Promise.reject(err);
142
164
  }
143
165
 
144
166
  // 4) 403 — вытаскиваем только path без query/hash
145
167
  if (status === 403) {
168
+ markErrorAsHandled(err, status);
146
169
  try {
147
170
  const rawUrl = response.config?.url ?? '';
148
171
  const urlObj = new URL(rawUrl, window.location.origin);
@@ -157,18 +180,21 @@ export default function setupInterceptors(axios: AxiosInstance): void {
157
180
 
158
181
  // 5) 404
159
182
  if (status === 404 && !isSilent) {
183
+ markErrorAsHandled(err, status);
160
184
  showToaster('error', appContextStore.t('error.404'), 5000);
161
185
  return Promise.reject(err);
162
186
  }
163
187
 
164
188
  // 6) 413
165
189
  if (status === 413) {
190
+ markErrorAsHandled(err, status);
166
191
  showToaster('error', appContextStore.t('error.exceedUploadLimitFile'), 5000);
167
192
  return Promise.reject(err);
168
193
  }
169
194
 
170
195
  // 7) 500 — явная обработка
171
196
  if (status === 500) {
197
+ markErrorAsHandled(err, status);
172
198
  const errorMessage = extractErrorMessage(data, status, appContextStore);
173
199
  showToaster('error', String(errorMessage), 5000);
174
200
  return Promise.reject(err);
@@ -321,7 +321,27 @@ export const ESBDMessage = (ESBDObject: any, initialPoint: any) => {
321
321
  export const ErrorHandler = (err: unknown, errorText?: string) => {
322
322
  console.error('[ErrorHandler]', err);
323
323
 
324
+ const isHandledByInterceptor = (error: unknown, status?: number) => {
325
+ if (!error || typeof error !== 'object') return false;
326
+
327
+ const localError = error as AxiosError & {
328
+ handledByInterceptor?: boolean;
329
+ handledStatus?: number;
330
+ config?: Record<string, unknown>;
331
+ };
332
+
333
+ const handledOnError = localError.handledByInterceptor === true;
334
+ const handledOnConfig = localError.config?.handledByInterceptor === true;
335
+ const markedStatus = Number(localError.handledStatus ?? localError.config?.handledStatus ?? NaN);
336
+
337
+ return (handledOnError || handledOnConfig) && (status === undefined || markedStatus === status);
338
+ };
339
+
324
340
  try {
341
+ if (isHandledByInterceptor(err)) {
342
+ return false;
343
+ }
344
+
325
345
  if (typeof err === 'string') {
326
346
  showToaster('error', err, 6000);
327
347
  return false;
@@ -342,6 +362,10 @@ export const ErrorHandler = (err: unknown, errorText?: string) => {
342
362
  return false;
343
363
  }
344
364
 
365
+ if (isHandledByInterceptor(err, response.status)) {
366
+ return false;
367
+ }
368
+
345
369
  const responseData = response.data as unknown;
346
370
 
347
371
  if (responseData instanceof ArrayBuffer) {
@@ -1049,7 +1073,7 @@ export class RoleController {
1049
1073
  isFinCenter = () => this.isRole(constants.roles.FinCenter);
1050
1074
  isSupervisor = () => this.isRole(constants.roles.Supervisor);
1051
1075
  isHeadManager = () => this.isRole(constants.roles.HeadManager);
1052
- isHeadOfDepartment = () => this.isRole(constants.roles.HeadOfDepartment);
1076
+ isHeadOfDepartmentSettlementLosses = () => this.isRole(constants.roles.HeadOfDepartmentSettlementLosses);
1053
1077
  isBranchDirector = () => this.isRole(constants.roles.BranchDirector);
1054
1078
  isRegionDirector = () => this.isRole(constants.roles.RegionDirector);
1055
1079
  isUSNSACCINS = () => this.isRole(constants.roles.USNSACCINS);
@@ -1103,7 +1127,7 @@ export class RoleController {
1103
1127
  this.isSanctioner3() ||
1104
1128
  this.isRegisterSanctioner() ||
1105
1129
  this.isDeputyDirector() ||
1106
- this.isHeadOfDepartment() ||
1130
+ this.isHeadOfDepartmentSettlementLosses() ||
1107
1131
  baseAccessRoles,
1108
1132
  toReinsurance: this.isReInsurer() || this.isAdjuster() || this.isHeadAdjuster() || baseAccessRoles,
1109
1133
  toReporting:
@@ -1137,6 +1161,7 @@ export class RoleController {
1137
1161
  this.isAgentMycar() ||
1138
1162
  this.isManagerHalykBank() ||
1139
1163
  this.isHeadManager() ||
1164
+ this.isHeadOfDepartmentSettlementLosses() ||
1140
1165
  this.isServiceManager() ||
1141
1166
  this.isUSNSsanctioner() ||
1142
1167
  this.isUnderwriter() ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hl-core",
3
- "version": "0.0.10-beta.82",
3
+ "version": "0.0.10-beta.83",
4
4
  "license": "MIT",
5
5
  "private": false,
6
6
  "main": "nuxt.config.ts",
package/types/enum.ts CHANGED
@@ -139,7 +139,7 @@ export enum Roles {
139
139
  Sanctioner3 = 'Sanctioner3',
140
140
  RegisterSanctioner = 'RegisterSanctioner',
141
141
  DeputyDirectorSettlementLosses = 'DeputyDirectorSettlementLosses',
142
- HeadOfDepartment = 'HeadOfDepartment',
142
+ HeadOfDepartmentSettlementLosses = 'HeadOfDepartmentSettlementLosses',
143
143
  }
144
144
 
145
145
  export enum Statuses {