MCPcopy Create free account
hub / github.com/apitable/apitable / get

Function get

packages/core/src/utils/error_capture.ts:35–89  ·  view source on GitHub ↗
(this: T)

Source from the content-addressed store, hash-verified

33 configurable: true,
34
35 get(this: T) {
36 const boundFn = fn.bind(this);
37 Reflect.defineProperty(this, name, {
38 value: boundFn,
39 configurable: true,
40 writable: true,
41 });
42 const i18nMessage = (code: number, message: string) => {
43 switch (code) {
44 case 50000:
45 return t(Strings.socket_error_server);
46 case 50001:
47 return t(Strings.socket_error_network);
48 case StatusCode.FRONT_VERSION_ERROR:
49 return t(Strings.front_version_error_desc);
50 }
51 return message;
52 };
53
54 const getErrorType = (code: string) => {
55 if ([OVER_LIMIT_PER_SHEET_RECORDS, OVER_LIMIT_SPACE_RECORDS, OVER_LIMIT_GANTT_VIEW_NUMBER, OVER_LIMIT_CALENDAR_NUMBER].includes(code)) {
56 return 'subscribeUsage';
57 }
58 return;
59 };
60
61 const onError = (e: any) => {
62 const code = e.code || ErrorCode.CollaSyncError;
63 this.event.onError && this.event.onError({
64 ...e,
65 type: ErrorType.CollaError,
66 code: code,
67 message: i18nMessage(code, e.message),
68 }, getErrorType(code));
69
70 throw e;
71 };
72
73 return (...args: any[]) => {
74 try {
75
76 const promise = boundFn(...args);
77 // If it is a promise, you need to listen catch catch
78 if (promise instanceof Promise) {
79 promise.catch(e => {
80 onError(e);
81 });
82 }
83
84 return promise;
85 } catch (e) {
86 onError(e);
87 }
88 };
89 },
90 };
91 };
92};

Callers 6

TaskBaseFunction · 0.50
styled.tsxFile · 0.50
getActivityListMethod · 0.50
retryAsyncFunction · 0.50
handleHealthyMethod · 0.50
showRecordHistoryMethod · 0.50

Calls 3

onErrorFunction · 0.70
bindMethod · 0.45
catchMethod · 0.45

Tested by

no test coverage detected