@etsoo/appscript 1.4.38 → 1.4.40
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.
- package/lib/cjs/app/CoreApp.d.ts +3 -3
- package/lib/cjs/app/CoreApp.js +14 -9
- package/lib/cjs/app/IApp.d.ts +11 -0
- package/lib/mjs/app/CoreApp.d.ts +3 -3
- package/lib/mjs/app/CoreApp.js +14 -9
- package/lib/mjs/app/IApp.d.ts +11 -0
- package/package.json +1 -1
- package/src/app/CoreApp.ts +17 -9
- package/src/app/IApp.ts +16 -0
package/lib/cjs/app/CoreApp.d.ts
CHANGED
|
@@ -182,14 +182,14 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
182
182
|
/**
|
|
183
183
|
* Setup Api error handler
|
|
184
184
|
* @param api Api
|
|
185
|
-
* @param
|
|
185
|
+
* @param handlerFor401 Handler for 401 error
|
|
186
186
|
*/
|
|
187
|
-
|
|
187
|
+
setApiErrorHandler(api: IApi, handlerFor401?: boolean | (() => Promise<void>)): void;
|
|
188
188
|
/**
|
|
189
189
|
* Setup Api loading
|
|
190
190
|
* @param api Api
|
|
191
191
|
*/
|
|
192
|
-
|
|
192
|
+
setApiLoading(api: IApi): void;
|
|
193
193
|
/**
|
|
194
194
|
* Api init call
|
|
195
195
|
* @param data Data
|
package/lib/cjs/app/CoreApp.js
CHANGED
|
@@ -297,22 +297,27 @@ class CoreApp {
|
|
|
297
297
|
/**
|
|
298
298
|
* Setup Api error handler
|
|
299
299
|
* @param api Api
|
|
300
|
-
* @param
|
|
300
|
+
* @param handlerFor401 Handler for 401 error
|
|
301
301
|
*/
|
|
302
|
-
setApiErrorHandler(api,
|
|
302
|
+
setApiErrorHandler(api, handlerFor401) {
|
|
303
303
|
api.onError = (error) => {
|
|
304
304
|
// Error code
|
|
305
305
|
const status = error.response
|
|
306
306
|
? api.transformResponse(error.response).status
|
|
307
307
|
: undefined;
|
|
308
|
-
if (status === 401
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
308
|
+
if (status === 401) {
|
|
309
|
+
if (handlerFor401 === false)
|
|
310
|
+
return;
|
|
311
|
+
if (typeof handlerFor401 === 'function') {
|
|
312
|
+
handlerFor401();
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
this.tryLogin();
|
|
316
|
+
}
|
|
317
|
+
return;
|
|
315
318
|
}
|
|
319
|
+
// Report the error
|
|
320
|
+
this.notifier.alert(this.formatError(error));
|
|
316
321
|
};
|
|
317
322
|
}
|
|
318
323
|
/**
|
package/lib/cjs/app/IApp.d.ts
CHANGED
|
@@ -448,6 +448,17 @@ export interface IApp {
|
|
|
448
448
|
* @param props Props
|
|
449
449
|
*/
|
|
450
450
|
refreshToken<D extends object = {}>(props?: RefreshTokenProps<D>): Promise<boolean>;
|
|
451
|
+
/**
|
|
452
|
+
* Setup Api error handler
|
|
453
|
+
* @param api Api
|
|
454
|
+
* @param handlerFor401 Handler for 401 error
|
|
455
|
+
*/
|
|
456
|
+
setApiErrorHandler(api: IApi, handlerFor401?: boolean | (() => Promise<void>)): void;
|
|
457
|
+
/**
|
|
458
|
+
* Setup Api loading
|
|
459
|
+
* @param api Api
|
|
460
|
+
*/
|
|
461
|
+
setApiLoading(api: IApi): void;
|
|
451
462
|
/**
|
|
452
463
|
* Signout, with userLogout and toLoginPage
|
|
453
464
|
*/
|
package/lib/mjs/app/CoreApp.d.ts
CHANGED
|
@@ -182,14 +182,14 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
182
182
|
/**
|
|
183
183
|
* Setup Api error handler
|
|
184
184
|
* @param api Api
|
|
185
|
-
* @param
|
|
185
|
+
* @param handlerFor401 Handler for 401 error
|
|
186
186
|
*/
|
|
187
|
-
|
|
187
|
+
setApiErrorHandler(api: IApi, handlerFor401?: boolean | (() => Promise<void>)): void;
|
|
188
188
|
/**
|
|
189
189
|
* Setup Api loading
|
|
190
190
|
* @param api Api
|
|
191
191
|
*/
|
|
192
|
-
|
|
192
|
+
setApiLoading(api: IApi): void;
|
|
193
193
|
/**
|
|
194
194
|
* Api init call
|
|
195
195
|
* @param data Data
|
package/lib/mjs/app/CoreApp.js
CHANGED
|
@@ -271,22 +271,27 @@ export class CoreApp {
|
|
|
271
271
|
/**
|
|
272
272
|
* Setup Api error handler
|
|
273
273
|
* @param api Api
|
|
274
|
-
* @param
|
|
274
|
+
* @param handlerFor401 Handler for 401 error
|
|
275
275
|
*/
|
|
276
|
-
setApiErrorHandler(api,
|
|
276
|
+
setApiErrorHandler(api, handlerFor401) {
|
|
277
277
|
api.onError = (error) => {
|
|
278
278
|
// Error code
|
|
279
279
|
const status = error.response
|
|
280
280
|
? api.transformResponse(error.response).status
|
|
281
281
|
: undefined;
|
|
282
|
-
if (status === 401
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
282
|
+
if (status === 401) {
|
|
283
|
+
if (handlerFor401 === false)
|
|
284
|
+
return;
|
|
285
|
+
if (typeof handlerFor401 === 'function') {
|
|
286
|
+
handlerFor401();
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
this.tryLogin();
|
|
290
|
+
}
|
|
291
|
+
return;
|
|
289
292
|
}
|
|
293
|
+
// Report the error
|
|
294
|
+
this.notifier.alert(this.formatError(error));
|
|
290
295
|
};
|
|
291
296
|
}
|
|
292
297
|
/**
|
package/lib/mjs/app/IApp.d.ts
CHANGED
|
@@ -448,6 +448,17 @@ export interface IApp {
|
|
|
448
448
|
* @param props Props
|
|
449
449
|
*/
|
|
450
450
|
refreshToken<D extends object = {}>(props?: RefreshTokenProps<D>): Promise<boolean>;
|
|
451
|
+
/**
|
|
452
|
+
* Setup Api error handler
|
|
453
|
+
* @param api Api
|
|
454
|
+
* @param handlerFor401 Handler for 401 error
|
|
455
|
+
*/
|
|
456
|
+
setApiErrorHandler(api: IApi, handlerFor401?: boolean | (() => Promise<void>)): void;
|
|
457
|
+
/**
|
|
458
|
+
* Setup Api loading
|
|
459
|
+
* @param api Api
|
|
460
|
+
*/
|
|
461
|
+
setApiLoading(api: IApi): void;
|
|
451
462
|
/**
|
|
452
463
|
* Signout, with userLogout and toLoginPage
|
|
453
464
|
*/
|
package/package.json
CHANGED
package/src/app/CoreApp.ts
CHANGED
|
@@ -455,22 +455,30 @@ export abstract class CoreApp<
|
|
|
455
455
|
/**
|
|
456
456
|
* Setup Api error handler
|
|
457
457
|
* @param api Api
|
|
458
|
-
* @param
|
|
458
|
+
* @param handlerFor401 Handler for 401 error
|
|
459
459
|
*/
|
|
460
|
-
|
|
460
|
+
public setApiErrorHandler(
|
|
461
|
+
api: IApi,
|
|
462
|
+
handlerFor401?: boolean | (() => Promise<void>)
|
|
463
|
+
) {
|
|
461
464
|
api.onError = (error: ApiDataError) => {
|
|
462
465
|
// Error code
|
|
463
466
|
const status = error.response
|
|
464
467
|
? api.transformResponse(error.response).status
|
|
465
468
|
: undefined;
|
|
466
469
|
|
|
467
|
-
if (status === 401
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
470
|
+
if (status === 401) {
|
|
471
|
+
if (handlerFor401 === false) return;
|
|
472
|
+
if (typeof handlerFor401 === 'function') {
|
|
473
|
+
handlerFor401();
|
|
474
|
+
} else {
|
|
475
|
+
this.tryLogin();
|
|
476
|
+
}
|
|
477
|
+
return;
|
|
473
478
|
}
|
|
479
|
+
|
|
480
|
+
// Report the error
|
|
481
|
+
this.notifier.alert(this.formatError(error));
|
|
474
482
|
};
|
|
475
483
|
}
|
|
476
484
|
|
|
@@ -478,7 +486,7 @@ export abstract class CoreApp<
|
|
|
478
486
|
* Setup Api loading
|
|
479
487
|
* @param api Api
|
|
480
488
|
*/
|
|
481
|
-
|
|
489
|
+
public setApiLoading(api: IApi) {
|
|
482
490
|
// onRequest, show loading or not, rewrite the property to override default action
|
|
483
491
|
api.onRequest = (data) => {
|
|
484
492
|
if (data.showLoading == null || data.showLoading) {
|
package/src/app/IApp.ts
CHANGED
|
@@ -606,6 +606,22 @@ export interface IApp {
|
|
|
606
606
|
props?: RefreshTokenProps<D>
|
|
607
607
|
): Promise<boolean>;
|
|
608
608
|
|
|
609
|
+
/**
|
|
610
|
+
* Setup Api error handler
|
|
611
|
+
* @param api Api
|
|
612
|
+
* @param handlerFor401 Handler for 401 error
|
|
613
|
+
*/
|
|
614
|
+
setApiErrorHandler(
|
|
615
|
+
api: IApi,
|
|
616
|
+
handlerFor401?: boolean | (() => Promise<void>)
|
|
617
|
+
): void;
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* Setup Api loading
|
|
621
|
+
* @param api Api
|
|
622
|
+
*/
|
|
623
|
+
setApiLoading(api: IApi): void;
|
|
624
|
+
|
|
609
625
|
/**
|
|
610
626
|
* Signout, with userLogout and toLoginPage
|
|
611
627
|
*/
|