Yuki Takei пре 7 месеци
родитељ
комит
c40f64a708
2 измењених фајлова са 9 додато и 8 уклоњено
  1. 2 4
      apps/app/src/client/util/apiv3-client.ts
  2. 7 4
      packages/core/src/models/vo/error-apiv3.ts

+ 2 - 4
apps/app/src/client/util/apiv3-client.ts

@@ -2,8 +2,6 @@
 import type { AxiosResponse } from 'axios';
 import type { AxiosResponse } from 'axios';
 import urljoin from 'url-join';
 import urljoin from 'url-join';
 
 
-// eslint-disable-next-line no-restricted-imports
-
 import { toArrayIfNot } from '~/utils/array-utils';
 import { toArrayIfNot } from '~/utils/array-utils';
 import axios from '~/utils/axios';
 import axios from '~/utils/axios';
 import loggerFactory from '~/utils/logger';
 import loggerFactory from '~/utils/logger';
@@ -15,9 +13,9 @@ const logger = loggerFactory('growi:apiv3');
 
 
 const apiv3ErrorHandler = (_err: any): any[] => {
 const apiv3ErrorHandler = (_err: any): any[] => {
   // extract api errors from general 400 err
   // extract api errors from general 400 err
-  const err = _err.response ? _err.response.data.errors : _err;
+  const err = axios.isAxiosError(_err) ? _err.response?.data.errors : _err;
   const errs = toArrayIfNot(err);
   const errs = toArrayIfNot(err);
-  const errorInfo = _err.response ? _err.response.data.info : undefined;
+  const errorInfo = axios.isAxiosError(_err) ? _err.response?.data.info : undefined;
 
 
   for (const err of errs) {
   for (const err of errs) {
     logger.error(err.message);
     logger.error(err.message);

+ 7 - 4
packages/core/src/models/vo/error-apiv3.ts

@@ -1,15 +1,14 @@
-export class ErrorV3 extends Error {
+export class ErrorV3<ARGS = any> extends Error {
   code: string;
   code: string;
 
 
   // biome-ignore lint/suspicious/noExplicitAny: ignore
   // biome-ignore lint/suspicious/noExplicitAny: ignore
-  args?: any;
+  args?: ARGS;
 
 
   constructor(
   constructor(
     message = '',
     message = '',
     code = '',
     code = '',
     stack = undefined,
     stack = undefined,
-    // biome-ignore lint/suspicious/noExplicitAny: ignore
-    args: any = undefined,
+    args: ARGS | undefined = undefined,
   ) {
   ) {
     super(); // do not provide message to the super constructor
     super(); // do not provide message to the super constructor
     this.message = message;
     this.message = message;
@@ -18,3 +17,7 @@ export class ErrorV3 extends Error {
     this.args = args;
     this.args = args;
   }
   }
 }
 }
+
+export const isErrorV3 = <ARGS = any>(obj: any): obj is ErrorV3<ARGS> => {
+  return obj != null && typeof obj === 'object' && 'code' in obj && 'message' in obj;
+}