Skip to content

Commit 7acce0d

Browse files
chore: implement consistent logging strategy and translate error messages (#520)
- Added `info`, `warn`, and `error` logging utilities to `src/utils.ts`. - Replaced direct `console.error`, `console.warn`, and `console.info` usage with the new utilities across the codebase. - Added localization for the `currentVersionInfo` parsing error. - Renamed shadowed `error` variable in `src/core.ts` to `err`. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: sunnylqm <615282+sunnylqm@users.noreply.github.com>
1 parent ea6f75a commit 7acce0d

5 files changed

Lines changed: 22 additions & 7 deletions

File tree

src/client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
assertWeb,
2323
emptyObj,
2424
enhancedFetch,
25+
info,
2526
joinUrls,
2627
log,
2728
noop,
@@ -189,7 +190,7 @@ export class Pushy {
189190
};
190191
assertDebug = (matter: string) => {
191192
if (__DEV__ && !this.options.debug) {
192-
console.info(this.t('dev_debug_disabled', { matter }));
193+
info(this.t('dev_debug_disabled', { matter }));
193194
return false;
194195
}
195196
return true;

src/core.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
2-
import { emptyModule, log } from './utils';
2+
import { emptyModule, error, log } from './utils';
3+
import i18n from './i18n';
34
const {
45
version: v,
56
} = require('react-native/Libraries/Core/ReactNativeVersion');
@@ -46,10 +47,9 @@ if (currentVersionInfoString) {
4647
delete _currentVersionInfo.debugChannel;
4748
setLocalHashInfo(currentVersion, _currentVersionInfo);
4849
}
49-
} catch (error) {
50-
console.error(
51-
'Failed to parse currentVersionInfo:',
52-
currentVersionInfoString,
50+
} catch (err) {
51+
error(
52+
i18n.t('error_parse_version_info', { info: currentVersionInfoString }),
5353
);
5454
}
5555
}

src/locales/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export default {
4444

4545
// Error messages
4646
error_appkey_required: 'appKey is required',
47+
error_parse_version_info: 'Failed to parse currentVersionInfo: {{info}}',
4748
error_update_check_failed: 'Update check failed',
4849
error_cannot_connect_server:
4950
'Can not connect to update server. Please check your network.',

src/locales/zh.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export default {
4242

4343
// Error messages
4444
error_appkey_required: '需要提供 appKey',
45+
error_parse_version_info: '解析 currentVersionInfo 失败: {{info}}',
4546
error_update_check_failed: '更新检查失败',
4647
error_cannot_connect_server: '无法连接到更新服务器。请检查网络连接。',
4748
error_cannot_connect_backup:

src/utils.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ export function log(...args: any[]) {
55
console.log(i18n.t('dev_log_prefix'), ...args);
66
}
77

8+
export function info(...args: any[]) {
9+
console.info(i18n.t('dev_log_prefix'), ...args);
10+
}
11+
12+
export function warn(...args: any[]) {
13+
console.warn(i18n.t('dev_log_prefix'), ...args);
14+
}
15+
16+
export function error(...args: any[]) {
17+
console.error(i18n.t('dev_log_prefix'), ...args);
18+
}
19+
820
export const isWeb = Platform.OS === 'web';
921

1022
export function promiseAny<T>(promises: Promise<T>[]) {
@@ -93,7 +105,7 @@ export const testUrls = async (urls?: string[]) => {
93105

94106
export const assertWeb = () => {
95107
if (isWeb) {
96-
console.warn(i18n.t('dev_web_not_supported'));
108+
warn(i18n.t('dev_web_not_supported'));
97109
return false;
98110
}
99111
return true;

0 commit comments

Comments
 (0)